Autocomplete (with POJO) initialization fails in M4..

UI Components for JSF
Post Reply
svenkateshkumar
Posts: 1
Joined: 02 Dec 2011, 11:45

06 Dec 2011, 06:06

Hi,

I am not able to initialize p:autoComplete component (with POJO collection) using the setter methods. Does any faces similar issues?? In the following sample, I m using a EmployeeBean(POJO) collection which needs to be auto completed. Would appreciate if any quick help/tips..

UI Controller

import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

@Controller(value="autocompleteBean")
@Scope(value="view")
public class SimpleAutoComplete {

private String employeeName;
private List<EmployeeBean> employeeBeanList;

public List<EmployeeBean> getEmployeeBeanList() {
return employeeBeanList;
}
public void setEmployeeBeanList(List<EmployeeBean> employeeBeanList) {
this.employeeBeanList = employeeBeanList;
}
public String getEmployeeName() {
return employeeName;
}
public void setEmployeeName(String employeeName) {
this.employeeName = employeeName;
}

public List<EmployeeBean> readEmployeeBean(String query){
return employeeBeanList;
}

@PostConstruct
public void init(){

employeeBeanList=new ArrayList<EmployeeBean>();
employeeBeanList.add(new EmployeeBean(1, "One"));
employeeBeanList.add(new EmployeeBean(2, "Two"));
employeeBeanList.add(new EmployeeBean(3, "Three"));

/ Pre-selection fails for autocomplete input component. Uncomment the following and you will see blank page.

// setEmployeeName("One");
}

}

UI Page
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<ui:define name="content">
<div class="entry">
<p:panel header="Simple Autocomplete">
<h:form>
<h:panelGrid columns="2">
<h:outputLabel value="POJO AutoComplete"/>
<p:autoComplete value="#{autocompleteBean.employeeName}"
var="employee" itemValue="#{employee.empName}" itemLabel="#{employee.empName}"
completeMethod="#{autocompleteBean.readEmployeeBean}"/>

<p:commandButton value="Save"/>
</h:panelGrid>
</h:form>
</p:panel>
</div>
</ui:define>
</ui:composition>

Employee Bean

public class EmployeeBean {
private long empNo;
private String empName;

public long getEmpNo() {
return empNo;
}
public void setEmpNo(long empNo) {
this.empNo = empNo;
}
public String getEmpName() {
return empName;
}
public void setEmpName(String empName) {
this.empName = empName;
}
public EmployeeBean(long empNo,String empName) {
this.empNo=empNo;
this.empName=empName;
}


}

VK
Tomcat 6, Primefaces 3.0.M4,
Spring 3.0, Windows

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 46 guests