0

我是 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)

我不明白为什么它将方法视为一种属性。有人可以帮助我进行正确的更改和解释。

4

2 回答 2

2

RichFaces 未正确安装。您的 RichFaces 标记基本上被解释为纯文本,可以UIInstructions在堆栈跟踪中识别:

at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:78)

这基本上与你会做的问题相同

<p>#{searchCity.searchCityByMatchChar}</p>

模板文本中的 EL 默认被解析为属性值表达式,需要一个 getter 方法。

验证您是否正确安装了 RichFaces。它是 7 个 JAR 文件/WEB-INF/lib

于 2013-02-09T11:03:22.890 回答
0

您的 bean 上没有方法searchCityByMatchChar。它被称为searchCityByMatchCharforauto。这可能是您的错误的根本原因。

于 2013-02-09T09:26:04.677 回答