Hello I have a component selectOneMenu from JSF Bootsfaces and I would like to fill it with values from backing bean.
This is what I have tried and it hasn`t worked:
This is the xhtml:
<b:selectOneMenu ajax="true" process="@this" label="Selecteaza CNP sau CUI">
<f:selectItems value="#{cereri.cnpcui}" var="beer"
itemValue="1" itemLabel="#{cereri.cnpcui}" />
</b:selectOneMenu>
This is the java bean:
@ManagedBean(name = "cereri", eager = true)
@RequestScoped
public class Cereri {
private List<String> cnpcui;
public Cereri() {
cnpcui = new ArrayList<>();
cnpcui.add("CUI");
cnpcui.add("CNP");
}
public List<String> getCnpcui() {
return cnpcui;
}
public void setCnpcui(List<String> cnpcui) {
this.cnpcui = cnpcui;
}
The dropdown displays both values on each row as an array: [CNP,CUI] on both rows. I would like one value on first row and second value on second row.
Thanks
You are not using the component correctly. When you reference itemLabel="#{cereri.cnpcui}"
you are telling the component to output the whole array.
To get the behaviour you are after, you need to do something like this;
<b:selectOneMenu ajax="true" process="@this" label="Selecteaza CNP sau CUI">
<f:selectItems value="#{cereri.cnpcui}" var="beer"
itemValue="#{beer}" itemLabel="#{beer}" />
</b:selectOneMenu>
Each item from the list referenced by the value
attribute (a string in this case) is placed in the locally scoped variable beer
. Referencing #{beer}
in the expression will therefore instruct the component to output the actual string.