I am trying to use primefaces autocomplete component in my project, in order to avoid writing specific converter to each list object I am trying to use omnifaces as suggested in here and here by 'BalusC', I tried to replicate exactly same way but could not able get this work. please review below code snippet and advice if I am missing anything here?
First part of the code [f:selectOneMenu] is working absolutely fine without anyissues
XHTML
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<ui:composition template="WEB-INF/layout/layout.xhtml">
<ui:define name="content">
<h:form>
<h:outputText id="selected_status"
value="#{mybean.objLuStatus.strDescColVal}" />
<!-- h:selectOneMenu Working fine -->
<h:selectOneMenu id="iterator2" value="#{mybean.objLuStatus}"
converter="omnifaces.SelectItemsConverter">
<f:selectItem itemLabel="Choose item" noSelectionOption="true" />
<f:selectItems value="#{mybean.lstStatus}" var="entity"
itemLabel="#{entity.strDescColVal}" itemValue="#{entity}" />
<f:ajax render="selected_status" />
</h:selectOneMenu>
<!-- p:autoComplete is NOT Working -->
<p:autoComplete id="iterator3" value="#{mybean.objLuStatus}"
converter="omnifaces.ListConverter" dropdown="true" var="entity"
itemLabel="#{entity.strDescColVal}"
placeholder="----- Select One -----" itemValue="#{entity}"
completeMethod="#{mybean.completeList}">
<f:ajax render="selected_status" />
</p:autoComplete>
<h:commandButton value="Submit" action="#{mybean.post}" />
</h:form>
</ui:define>
</ui:composition>
</html>
Managed Bean
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import com.ntr.foundation.model.LuStatus;
@ManagedBean(name = "mybean")
@ViewScoped
public class MyManagedBean extends BaseManagedBean implements Serializable {
List<LuStatus> lstStatus;
LuStatus objLuStatus;
@PostConstruct
public void init() {
lstStatus = new ArrayList<LuStatus>();
lstStatus.add(new LuStatus("1", "Draft", "DraftLong"));
lstStatus.add(new LuStatus("2", "Approved", "ApprovedLong"));
}
public List<LuStatus> getLstStatus() {
return lstStatus;
}
public void setLstStatus(List<LuStatus> lstStatus) {
this.lstStatus = lstStatus;
}
public void post() {
System.out.println("returned value " + objLuStatus);
}
public LuStatus getObjLuStatus() {
return objLuStatus;
}
public void setObjLuStatus(LuStatus objLuStatus) {
this.objLuStatus = objLuStatus;
}
public List<LuStatus> completeList(String strQuery) {
return lstStatus;
}
}
But I am getting below error...
Thanks in advance..
Caused by: java.lang.NullPointerException
at org.omnifaces.converter.ListConverter.getAsObject(ListConverter.java:39) [omnifaces-1.7.jar:1.7]
at org.primefaces.component.autocomplete.AutoCompleteRenderer.getConvertedValue(AutoCompleteRenderer.java:600) [primefaces-4.0.jar:4.0]
at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1046) [jsf-api-2.2.4.jar:2.2]
at javax.faces.component.UIInput.validate(UIInput.java:976) [jsf-api-2.2.4.jar:2.2]