Jayesh
Jayesh

Reputation: 6111

function not getting called in autocomplete jsf

I am new to jsf and trying to implement autocomplete box.

So here is what i did.

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>

I am getting error as :

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)

I am not getting why it is considering method as a property. can someone please help me with correct changes and explanation.

Upvotes: 0

Views: 518

Answers (2)

BalusC
BalusC

Reputation: 1108842

RichFaces is not properly installed. Your RichFaces tag is basically interpreted as plain text, which is recognizable as UIInstructions in the stack trace:

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

It's essentially the same problem as when you would do e.g.

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

EL in template text is by default resovled as a property value expression, requiring a getter method.

Verify if you installed RichFaces right. It are 7 JAR files in /WEB-INF/lib.

Upvotes: 2

chkal
chkal

Reputation: 5668

There is not method searchCityByMatchChar on your bean. It's called searchCityByMatchCharforauto. This may be the root cause of your error.

Upvotes: 0

Related Questions