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

4

1 に答える 1

2

myBean に「complete」プロパティがないというエラーが表示されています

財産?このアクション メソッドは、そもそもプロパティとして扱われるべきではありません。これは、 がメソッド式ではなく値式として扱われていることを示唆しています。#{myBean.complete}これは、プレーンな HTML で so のようにインライン化した場合とまったく同じです<p>#{myBean.complete}</p>。これは、<p:autoComplete>タグが JSF コンポーネントとしてまったく認識されておらず、プレーン テキスト/HTML として扱われていることを示しています。これは、PrimeFaces の taglib URI が間違っているか、JAR ファイルが Web アプリケーションのランタイム クラスパスに適切に配置されていないことを示しています。

少なくとも PrimeFaces バージョン 3.0 (古いバージョンでは taglib URI が異なります) を使用し、JAR ファイルが/WEB-INF/libwebapp のフォルダーに配置されていることを確認してください。

于 2012-08-29T12:26:09.690 に答える