问题
I am trying for too long to make an autocomplete custom suggestion demo. The demo is partially working as I can see the suggestions response in f12 debugger, but it is not showing in the drop down box. I am doing the following
POM:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<org.richfaces.version>4.3.3.Final</org.richfaces.version>
</properties>
<repositories>
<repository>
<id>org.openfaces</id>
<url>http://repository.openfaces.org/repository</url>
</repository>
<repository>
<id>jfree</id>
<url>http://www.ibiblio.org/maven/jfree/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.richfaces</groupId>
<artifactId>richfaces-bom</artifactId>
<version>${org.richfaces.version}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.richfaces.ui</groupId>
<artifactId>richfaces-components-ui</artifactId>
<version>${org.richfaces.version}</version>
</dependency>
<dependency>
<groupId>org.richfaces.core</groupId>
<artifactId>richfaces-core-impl</artifactId>
<version>${org.richfaces.version}</version>
</dependency>
the bean:
@ManagedBean
@RequestScoped
public class TagCollector implements Serializable{
private static final long serialVersionUID = 4930140495481611695L;
String tagName;
public Converter getTagNameConverter(){
return new Converter() {
@Override
public String getAsString(FacesContext context, UIComponent converter, Object value) {
System.out.println("getAsString=" +(String)value);
return (String)value;
}
@Override
public Object getAsObject(FacesContext context, UIComponent converter, String value) {
System.out.println("getAsObject=" +value);
return value;
}
};
}
public List<String> getSuggestedTags(){
String searchString = Faces.var("searchString", String.class);
System.out.println("getSuggestedTags searchString="+ searchString);
List<String> suggestedTags = Arrays.asList(new String[]{"ford", "mazda", "fiat"});
return suggestedTags;
}
public String getTagName() {
return tagName;
}
public void setTagName(String tagName) {
this.tagName = tagName;
}
}
the xhtml:
<h:form>
<h:outputText value="Enter state" />
<rich:autocomplete mode="ajax" minChars="1" showButton="true"
autocompleteMethod="#{userBean.autocomplete}">
</rich:autocomplete>
</h:form>
the faces config:
<managed-bean>
<managed-bean-name>tagCollector</managed-bean-name>
<managed-bean-class>org.taagad.tag.model.TagCollector</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
I really search the web for hours getting nowhere, any idea will be helpful.
回答1:
I solved this issue! it is working on jsf 2.1.25. Same issue was with RichFaces, it appears both implementations are sensitive to the same issue/bug with jsf iml and api. That's the pom on my project:
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1.25</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.1.25</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>javax.portlet</groupId>
<artifactId>portlet-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
来源:https://stackoverflow.com/questions/18499184/richfaces-4-autocomplete-is-not-showing-suggestions