selectItems of selectOneMenu with param in JSF 2.0
I have dynamically generated form therefore i can't directly take data for my jsf components. I wander if there is a way to get selectItems with 开发者_如何转开发param transferred to method? for example: and it will be invoke getItems(String a) method
or may be use somehow.
Is it possible? Is there other ways to parametrize getters and setters?
Just call the method directly, rather than relying on the javabeans property naming convention.
ie. rather than:
<f:selectItems value="#{someBean.list}" />
do:
<f:selectItems value="#{someBean.getList(myparamter)}" />
Where the getList
method of your backing bean takes an argument.
I think it can help you.
All you need to do is a
public class SomeBean{
public List<SelectItem> getList(){
List<ItemType> list = getItemsFromSomewhereElse();
List<SelectItem> resultList = new ArrayList<SelectItem>();
for (ItemType it : list){
SelectItem item = new SelectItem(it.getKey(), it.getValue());
resultList.add(item);
}
return resultList;
}
}
on xhtml you do this:
<h:selectOneMenu id="selectItem"
value="#{someBean.itemThatIsGoingToBeFilled}">
<f:selectItems
value="#{someBean.list}" />
</h:selectOneMenu>
There`s a Small tutorial here.
精彩评论