【发布时间】:2013-02-22 12:23:51
【问题描述】:
当我从我的 selectOneMenu 中选择另一个皮肤时,我想更改 inputTexts 的值。 一切都很好,我的转换器从菜单中返回了正确的对象,但是 inputTexts 没有更新。
<h:form>
<h:selectOneMenu id="dropdownSkin"
value="#{helloBean.currentSkin}" defaultLabel="Select a skin.."
valueChangeListener="#{helloBean.skinValueChanged}" immediate="true"
onchange="this.form.submit()" converter="SkinConverter" >
<f:selectItems value="#{helloBean.mySkinsSI}" var="c"
itemValue="#{c.value}" />
</h:selectOneMenu>
<br />
<h:inputText id="name" value="#{helloBean.currentSkin.title}"></h:inputText>
<br />
<h:inputText id="tcolor" value="#{helloBean.currentSkin.titleBar.textColor}"></h:inputText>
<br />
<h:inputText id="bcolor" value="#{helloBean.currentSkin.titleBar.backgroundColorStart}"></h:inputText>
</h:form>
这是我的 Bean 的样子。我对其进行了调试,并且正确设置了 Object currentSkin。现在我需要知道如何更新文本字段的内容。
@ManagedBean
@SessionScoped
public class HelloBean implements Serializable {
private static final long serialVersionUID = 1L;
private List<ExtendedSkin> mySkins;
private List<SelectItem> mySkinsSI;
private ExtendedSkin currentSkin;
public void skinValueChanged(ValueChangeEvent e) {
currentSkin = (ExtendedSkin) e.getNewValue();
FacesContext.getCurrentInstance().renderResponse();
}
public List<ExtendedSkin> getMySkins() {
mySkins = XMLParser.readExtendedSkins();
return mySkins;
}
public List<SelectItem> getMySkinsSI() {
mySkinsSI = new LinkedList<SelectItem>();
for (ExtendedSkin s : getMySkins()) {
mySkinsSI.add(new SelectItem(s, s.getTitle()));
}
return mySkinsSI;
}
public void setMySkinsSI(List<SelectItem> myItems) {
this.mySkinsSI = myItems;
}
public ExtendedSkin getCurrentSkin() {
if (currentSkin == null) {
currentSkin = getMySkins().get(0);
}
return currentSkin;
}
public void setCurrentSkin(ExtendedSkin currentSkin) {
this.currentSkin = currentSkin;
}
}
【问题讨论】:
-
尝试将
<h:inputText>s 移出表单(作为第一次尝试)。这应该工作 -
天哪,你做到了,谢谢 :) 将其发布为答案,以便我接受它;)
-
好的,我会尝试解释问题和可能的解决方案。我在评论中提供的只是一个。
-
好的,稍后我想我必须再次将 inputTexts 放入表单中,因为我必须使用文本中的值进行预览,也许您也可以尝试使其工作; )
-
希望我的回答能让您明白一些概念,并展示使用 JSF 2 的优势。
标签: jsf selectonemenu