I have one p:selectManyMenu where I can choose multiple items, but I can't manage to get that values, it is always null so I'm not sure if I'm making mistake in processing components or my converter isn't good. Here is XHTML:
<h:form id="form">
<p:selectManyMenu id="advanced" value="#{pickListView.chosenItems}" converter="converterTest"
var="t" filter="true" filterMatchMode="contains" showCheckbox="true" >
<f:selectItems value="#{pickListView.allEquipment}" var="record" itemLabel="#{record.name}" itemValue="#{record}"/>
<p:column style="width:90%">
<h:outputText styleClass="f_text" value="#{t.name} - #{t.price}" />
</p:column>
</p:selectManyMenu>
<p:commandButton id="pojoSubmit" value="Spremi" oncomplete="PF('dlg').show()" actionListener="#{pickListView.saveRecords}" update=":form:table-wrapper" style="margin-top:5px" process="@this" />
<p:dialog header="Selected Values" modal="true" showEffect="fade" widgetVar="dlg" resizable="false">
<p:panelGrid columns="1" id="display" columnClasses="label,output">
<p:dataList value="#{pickListView.chosenItems}" var="t">
<h:outputText value="#{t}" />
</p:dataList>
</p:panelGrid>
</p:dialog>
</h:form>
So, my List<Equipment> chosenItems
should contain selected items but is always null. I don't know what should I've done wrong, maybe it's up to converter not managing to return asObject, but I print data from converted object before return
, as you can see below, and it's ok, so I'm very confused now...
Here is my Converter:
@FacesConverter(value = "converterTest")
public class ConverterTest implements Converter {
@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
if(value != null && value.trim().length() > 0) {
try {
SessionFactory factory = HibernateUtil.getSessionFactory();
Session session = factory.openSession();
Equipment o = (Equipment) session.get(Equipment.class, Integer.valueOf(value));
System.out.println("EQUIPMENT: " + o.getName() + " : " + o.getId());
return (Equipment) session.get(Equipment.class, Integer.valueOf(value));
} catch(NumberFormatException e) {
throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Conversion Error", "Not a valid equipment."));
}
}
else {
return null;
}
}
@Override
public String getAsString(FacesContext context, UIComponent component, Object object) {
return object instanceof Equipment ?
((Equipment) object).getId().toString() : "";
}
}
In bean I created two lists, one for all items and one for selected items with their getters and setters. Problem is that chosenItems list is always null.
private List<Equipment> chosenItems;
private List<Equipment> allEquipment;
//getters and setters
Any thoughts? If you need more details, feel free to ask. Thank you in advance!