函数未在自动完成jsf中调用

时间:2013-02-09 08:47:25

标签: ajax jsf jsf-2 autocomplete richfaces

我是jsf的新手,并尝试实现自动完成框。

所以这就是我所做的。

home.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;
     }
}

faces-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)

我不明白为什么将方法视为财产。有人可以帮我正确的改变和解释。

2 个答案:

答案 0 :(得分:2)

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

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

这与你做的事情基本上是同一个问题。

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

默认情况下,模板文本中的EL被重新恢复为属性值表达式,需要使用getter方法。

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

答案 1 :(得分:0)

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