Reputation: 317
i want to make simple DropDownList.
<p:selectOneMenu id="starter" value="#{reportRegisterManagedBean.starter}" style="width:160px" converter="#{reportStarterConverter}" required="true" requiredMessage="Select Report Starter">
<ui:repeat value="#{reportRegisterManagedBean.startersSelectItems}" var="dss">
<f:selectItem itemLabel="#{dss}" itemValue="#{dss}" itemDescription="TEST" />
</ui:repeat>
</p:selectOneMenu>
DropDownList
is enpty, if i use <f:selectItems>
instead of <ui:repeat>
works very well, but <f:selectItems>
Component itemDescription
=(this is simple tooltip analogy) not working. <f:selectItem>
Component itemDescription
=(this is simple tooltip analogy) working fine. That's why I decided to use the and <f:selectItem>
with its itemDescription
attribute.
Upvotes: 0
Views: 6031
Reputation: 2768
As you don't like String array. here is tested and working example with User class:
public class FilterBean {
private List<User> uList = new ArrayList<User>();
private User selectedUser = new User();
public List<User> getuList() {
User u1 = new User();
u1.setName("Tom");
u1.setDesc("worker");
User u2 = new User();
u2.setName("Peter");
u2.setDesc("owner");
uList.add(u1);
uList.add(u2);
return uList;
}
public void setuList(List<User> uList) {
this.uList = uList;
}
public User getSelectedUser() {
return selectedUser;
}
public void setSelectedUser(User selectedUser) {
this.selectedUser = selectedUser;
}
}
And this is JSF
<p:selectOneMenu value="#{filterBean.selectedUser}">
<f:selectItem itemLabel="Select One" itemValue="" />
<f:selectItems value="#{filterBean.uList}" var="n" itemValue="#{n}" itemDescription="#{n.desc}" itemLabel="#{n.name}" />
</p:selectOneMenu>
This shows desc for Tom and Peter :)
Upvotes: 2
Reputation: 1108722
The <f:selectItem>
needs to be added during view build time. However, the <ui:repeat>
runs during view render time. You need a repeater which runs during view build time. The JSTL <c:forEach>
is such one.
<p:selectOneMenu ...>
<c:forEach items="#{reportRegisterManagedBean.startersSelectItems}" var="dss">
<f:selectItem ... />
</c:forEach>
</p:selectOneMenu>
Alternatively, create a custom renderer. Here's an example which does exactly the same for <p:selectManyCheckbox>
: Primefaces tooltip for p:selectManyCheckbox
Upvotes: 3
Reputation: 2768
I have tried several examples and got this results:
I have this in pojo:
private String selectL;
private String[] listas;
public String[] getListas() {
listas = new String[2];
listas[0] = "pirmas";
listas[1] = "antras";
return listas;
}
and this jsf works (itemDescription must be String):
<p:selectOneMenu value="#{formBean.selectL}">
<f:selectItems value="#{filterBean.listas}" var="n" itemDescription="#{n}2" />
</p:selectOneMenu>
and this not :/ :
<p:selectOneMenu value="#{formBean.selectL}">
<f:selectItems value="#{filterBean.listas}" itemDescription="test2" />
</p:selectOneMenu>
EDIT:
After some test I just added var into second selectOneMenu and it WORKS now too:
<p:selectOneMenu value="#{formBean.selectL}">
<f:selectItems value="#{filterBean.listas}" var="n" itemDescription="test2" />
</p:selectOneMenu>
Upvotes: 1
Reputation: 3753
Here is how you create a drop-down list in primefaces
:
<p:selectOneMenu id="starter" value="#{reportRegisterManagedBean.starter.selectedItem}">
<f:selectItems value="#{reportRegisterManagedBean.starter.startersSelectItems}" />
</p:selectOneMenu>
Upvotes: 1