我在填充子 SelectOneMenu 的值时遇到问题。当我更改父 selectOneNode 中的值时,子 selectOneNode 中的值将被删除,而不是插入新值。
我的 xhtml 文件的一部分:
<a4j:region>
<h:selectOneMenu id="dict_trg" value="#{backingBean.trgDictId}" disabled="false" rendered="#{backingBean.itemEdited}">
<c:forEach var="dict" items="#{backingBean.dictionaries}">
<f:selectItem itemLabel="#{dict.name}" itemValue="#{dict.dicId}" />
</c:forEach>
<a4j:support ajaxSingle="true" event="onchange" reRender="entry_trg" />
</h:selectOneMenu>
<br />
<br />
<h:selectOneMenu id="entry_trg" value="#{backingBean.trgEntryId}" disabled="false" rendered="#{backingBean.itemEdited}">
<c:forEach var="entry" items="#{backingBean.trgDictionaryEntries}">
<f:selectItem itemLabel="#{entry.localizedName}" itemValue="#{entry.dntId}" />
</c:forEach>
</h:selectOneMenu>
</a4j:region>
还有一个方法负责获取 selectOneMenu 的列表条目
public List<Dictionary> getDictionaries(){
return getDictionaryDataManager().getDictionaries();
}
public List<DictionaryEntry> getTrgDictionaryEntries(){
getDictionaryDataManager().getDictionary(12);
}
我检查了这些方法,它们总是返回包含很少项目的列表。知道我做错了什么吗?
最佳答案
使用<f:selectItems>
如果您有一个项目集合,请使用 <c:forEach>
因为这就是破坏它的原因(你不能部分地重新渲染使用 <c:xyz>
构建的东西)。
<h:selectOneMenu id="dict_trg" value="#{backingBean.trgDictId}" disabled="false" rendered="#{backingBean.itemEdited}">
<f:selectItems var="dict" value="#{backingBean.dictionaries}" itemLabel="#{dict.name}" itemValue="#{dict.dicId}" />
<a4j:support ajaxSingle="true" event="onchange" reRender="entry_trg" />
</h:selectOneMenu>
关于java - 子 selectOneMenu JSF 1.2 的错误填充值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24151598/