2

I am trying to use autocomplete feature of primefaces but when I try to call bean method from my facelet then it shows an error that mybean has not such method
here is my code

Page.xhtml

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">
<h:head>

<title>Title</title>
</h:head>
<h:body>
<h:form id="form">  
    <p:panel header="AutoComplete" toggleable="true" id="panel">
        <h:panelGrid columns="2" cellpadding="5">  

            <h:outputLabel value="Simple :" for="acSimple" />  
            <p:autoComplete id="acSimple" value="#{myBean.txt1}"   
                    completeMethod="#{myBean.complete}"/>
                    </h:panelGrid>
                    </p:panel>
                    </h:form>
</h:body>
</html>

MyBean.java

import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
@ManagedBean(name="myBean")
@RequestScoped
public class MyBean {  

    private String txt1;  

    public List<String> complete(String query) {  
        List<String> results = new ArrayList<String>();  

        for (int i = 0; i < 10; i++) {  
            results.add(query + i);  
        }  

        return results;  
    }  

    public String getTxt1() {  
        return txt1;  
    }  

    public void setTxt1(String txt1) {  
        this.txt1 = txt1;  
    }  
}

So when i run this code, it is showing an error that myBean has no property 'complete'.I am using eclipse and latest version of primefaces.
Am i doing something wrong here?
please help
Thx

Petar Minchev
  • 46,889
  • 11
  • 103
  • 119
khan
  • 2,664
  • 8
  • 38
  • 64

1 Answers1

2

it is showing an error that myBean has no property 'complete'

Property? This action method shouldn't have been treated as a property in first place. This suggests that the #{myBean.complete} is been treated as a value expression instead of a method expression, exactly as would happen when you inline it in plain HTML like so <p>#{myBean.complete}</p>. This in turn suggests that the <p:autoComplete> tag isn't been recognized as a JSF component at all, but just treated as plain text/HTML. This in turn suggests that either the PrimeFaces taglib URI is wrong, or that the JAR file isn't properly been placed in the webapp's runtime classpath.

Make sure that you use at least PrimeFaces version 3.0 (in older versions, the taglib URI was different) and that the JAR file is been placed in /WEB-INF/lib folder of the webapp.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555