我是 jsf 的新手,正在尝试实现自动完成框。
所以这就是我所做的。
主页.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
<h:form>
<rich:autocomplete mode="ajax" layout="table" autocompleteMethod="#{searchCity.searchCityByMatchChar}" autocompleteList="#{searchCity.listOfCity}"
var="city" fetchValue="#{city.cityName}">
<rich:column>
#{city.cityName}
</rich:column>
</rich:autocomplete>
</h:form>
</ui:composition>
SearchCity.java
package com.cheapesto.cheapbilly.model;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import com.cheapesto.cheapbilly.dto.City;
@ManagedBean(name = "searchCity")
@SessionScoped
public class SearchCity {
private List<City> listOfCity;
public List<City> getListOfCity() {
return listOfCity;
}
public void setListOfCity(List<City> listOfCity) {
this.listOfCity = listOfCity;
}
public List<City> searchCityByMatchCharforauto() {
City city1 = new City();
city1.setCityId(1l);
city1.setCityName("New York");
City city2 = new City();
city2.setCityId(1l);
city2.setCityName("New Jesrsey");
City city3 = new City();
city3.setCityId(1l);
city3.setCityName("Seattle");
List<City> listOfCity = new ArrayList<City>();
listOfCity.add(city1);
listOfCity.add(city2);
listOfCity.add(city3);
return listOfCity;
}
}
面孔-config.xml
<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">
</faces-config>
我收到错误消息:
SEVERE: Servlet.service() for servlet [Faces Servlet] in context with path [/MyFirstFaces] threw exception [/faces/home.xhtml: Property 'searchCityByMatchChar' not found on type com.cheapesto.cheapbilly.model.SearchCity] with root cause
javax.el.ELException: /faces/home.xhtml: Property 'searchCityByMatchChar' not found on type com.cheapesto.cheapbilly.model.SearchCity
at com.sun.faces.facelets.compiler.AttributeInstruction.write(AttributeInstruction.java:91)
at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:78)
at com.sun.faces.facelets.compiler.UILeaf.encodeAll(UILeaf.java:179)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:164)
我不明白为什么它将方法视为一种属性。有人可以帮助我进行正确的更改和解释。