0
votes

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.

4
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 <ui:repeat> and <f:selectItem> with its itemDescription attribute.zura katsitadze
No need to post your question as comment, update you question insteadApurv
i'm try to ubdate but not updatede. there words <f:selectItems> not copi in original postzura katsitadze
I update your question with your comments, verify it and approve it.Apurv
Which field contains the list that you want to display in the DropDownList ? reportRegisterManagedBean.starter or reportRegisterManagedBean.startersSelectItems ?Apurv

4 Answers

3
votes

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

2
votes

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 :)

1
votes

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>  
1
votes

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>