0

私は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)

メソッドをプロパティとして検討している理由がわかりません。誰かが正しい変更と説明を手伝ってくれませんか。

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

searchCityByMatchCharあなたのBeanにはメソッドがありません。と呼ばれていsearchCityByMatchCharforautoます。これがエラーの根本原因である可能性があります。

于 2013-02-09T09:26:04.677 に答える