I am trying to build sample JSF 2 based autocomplete form. I am using primefaces 3.0.M2, JSF 2.1.2 libraries and JBoss 6.
I am using autoComplete component of primefaces but its not working. I am not getting any autocomplete text when I type in input text box.
I can see only following warning in JBoss console window :
19:40:56,874 WARN [Parameters] Parameters: Invalid chunk ignored.
My xhtml file looks like following :
<html 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.prime.com.tr/ui">
<h:head>
<title>sample auto completer</title>
</h:head>
<h:body>
<p:messages id="messages" />
<p:autoComplete id="AutoCompleter"
value="#{myBean.text}"
completeMethod="#{myBean.complete}"
onSelectUpdate="messages"/>
</h:body>
</html>
and java bean code is as follows :
package com.shekhar.jsf;
import java.util.ArrayList;
import java.util.List;
public class Bean {
private String text;
public List<String> complete(String val) {
List<String> lst = new ArrayList<String>();
for (int i = 0; i < 10; i++) {
lst.add(val + i);
}
return lst;
}
public void setText(String text) {
this.text = text;
}
public String getText() {
return text;
}
}
and my faces-config file contains following code :
<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
<managed-bean>
<managed-bean-name>myBean</managed-bean-name>
<managed-bean-class>com.shekhar.jsf.Bean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope&开发者_开发知识库gt;
</managed-bean>
</faces-config>
I dont understand which thing I am missing. Please help !!!
From the comment above as the accepted answer
You should see output in the console or in the log files for System.out.println(). If you did not then that means the complete method is not getting executed. It might be because you need to wrap your autoComplete and messages components in an
<h:form prependId="false">
.
Glad to see it worked for you. It may seem strange but there are a LOT of similarities between JSF and ASP.NET. I used to be an ASP.NET developer and I picked up JSF fairly easy. Good luck!
精彩评论