如果值在第一个中更改,我想更改SelectItem[]
第二个中的数组。SelectOneMenu
那可能吗?
问问题
6686 次
3 回答
2
我想通了,但我使用了 RichFaces 的 AJAX 功能,而不仅仅是 JSF。刚刚将标签添加到我的第一个 selectOneMenu 中,它可以工作:)
<a4j:support event="onchange" action="#{bean.onChange}"
reRender="otherSelectOneMenuID"/>
无论如何感谢您的回复!
于 2009-08-28T12:12:19.770 回答
1
如果您将值更改侦听器绑定到第一个 selectOneMenu,则应该是可能的。
从 ValueChangeEvent 获取新值并相应地更新列表。JSF 页面应该会显示更新后的列表。
希望这是有道理的!
于 2009-08-28T10:16:42.950 回答
0
好吧,我使用了 a4j,它起作用了。
<code>
//JSF
<h:outputLabel value="First selectOneMenu: "/>
<h:selectOneMenu value="#{yourBackingBean.selectedItem}">
<f:converter converterId="defaultConverter"/>
<f:selectItem id="df01" itemLabel="Item01" itemValue="1" />
<f:selectItem id="df02" itemLabel="Item02" itemValue="2" />
<f:selectItem id="df03" itemLabel="Item03" itemValue="3" />
<a4j:support event="onchange" reRender="secondSelectOneMenu"/> //secondSelectOneMenu is the id of the dropdown you want to change
</h:selectOneMenu>
<h:outputLabel value="Second selectOneMenu: "/>
<h:selectOneMenu value="#{yourBackingBean.attributeToStoreSelectedValue}" id="secondSelectOneMenu">
<f:converter converterId="defaultConverter"/>
<f:selectItem id="df00" itemLabel="Select" itemValue="0" /> //Default value
<f:selectItems value="#{yourBackingBean.returnByChoice}" />
</h:selectOneMenu>
//Converter
public class DefaultConverter implements Converter {
public Object getAsObject(FacesContext ctx, UIComponent component, String value) {
return value;
}
public String getAsString(FacesContext ctx, UIComponent component, Object value) {
String label = "";
if (value != null) {
label = value.toString();
}
return label;
}
}
//Backing Bean Sample
public List<SelectItem> returnByChoice() { //it must return a list of SelectItems so it can be displayed on the jsf page
String id = (String) getSelectedItem(); //this is the value chosen from the first dropDownMenu wich selectedItem is the attribute onthe binding of the first dropDownMenu.
ArrayList<SelectItem> arrItems = new ArrayList<SelectItem>();
if (id != null) {
List<YourClass> yourObjectList = yourDao.findAllItemsFromType(new Integer(id));
Iterator<YourClass> iterator = yourObjectList.iterator();
String tempName = "";
String tempId = "";
YourClass tempYourObject = null;
while (iterator.hasNext()) {
tempYourObject = iterator.next();
tempId = String.valueOf(tempYourObject.getId());
tempName = tempYourObject.getName();
arrItems.add(new SelectItem(tempId, tempName));
}
}
return arrProfiles;
}
</code>
于 2010-06-08T17:38:09.830 回答