Reputation: 541
I want to make Checkbox menu and display data in dataList. Here is my xhtml:
<h:form>
<h:panelGrid columns="3" cellpadding="5">
<h:outputLabel for="menu" value="Demonstratori :" />
<p:selectCheckboxMenu id="menu" value="#{nastavnik.odabraniDemonstratori}" label="Demonstratori:"
filter="true" filterMatchMode="startsWith" panelStyle="width:250px">
<f:selectItems value="#{nastavnik.sviDemonstratori}" var="demons" itemLabel="#{demons.ime} #{demons.prezime}" itemValue="#{demons}" />
</p:selectCheckboxMenu>
<p:commandLink value="Submit" update="display" />
</h:panelGrid>
<p:outputPanel id="display" style="width:250px;padding-left:5px;margin-top:10px">
<p:dataList value="#{nastavnik.odabraniDemonstratori}" var="d" type="ordered" emptyMessage="Nema odabranih demonstratora">
#{d.ime}"
</p:dataList>
</p:outputPanel>
</h:form>
Here is important code from Nastavnik bean :
private ArrayList<Demonstrator> odabraniDemonstratori;
public void setOdabraniDemonstratori(ArrayList<Demonstrator> odabraniDemonstratori) {
this.odabraniDemonstratori = odabraniDemonstratori;
}
public ArrayList<Demonstrator> getOdabraniDemonstratori() {
return odabraniDemonstratori;
}
Demonstrator bean has property ime
. Everything works good, but when I try to show data in dataList with #{d.ime}
, I am getting this error:
/unoslabvezbe.xhtml @84,49 value="#{d.ime}": Property 'ime' not found on type java.lang.String
d
property is type Demonstrator not String. Any help ?
Upvotes: 0
Views: 762
Reputation: 6040
When using a selection component (such as p:selectCheckboxMenu
or p:pickList
), you need a converter to handle complex (= not a simple String) Java objects as values of f:selectItems
. A converter will serialize and deserialize your entity Demonstrator
.
Therefore you need to add the converter
attribute for your p:selectCheckboxMenu
and reference your own converter, or even better, use the ready-to-use SelectItemsConverter
(showcase link) provided by Omnifaces, a great utility library for JSF developers (installation is straightforward: add the .jar file or add a new dependency in Maven).
<p:selectCheckboxMenu id="menu" value="#{nastavnik.odabraniDemonstratori}" converter="omnifaces.SelectItemsConverter" label="Demonstratori:" filter="true" filterMatchMode="startsWith" panelStyle="width:250px">
<f:selectItems value="#{nastavnik.sviDemonstratori}" var="demons" itemLabel="#{demons.ime} #{demons.prezime}" itemValue="#{demons}" />
</p:selectCheckboxMenu>
Note: To learn more about designing your own converter (not the way to go):
Upvotes: 2