我正在尝试使用 primefaces 的自动完成功能,但是当我尝试从 Facelet 调用 bean 方法时,它会显示一个错误,表明 mybean 没有这样的方法
这是我的代码
页面.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;
}
}
因此,当我运行此代码时,它显示一个错误,即 myBean 没有属性“完整”。我正在使用 Eclipse 和最新版本的 primefaces。
我在这里做错了什么吗?
请帮忙
Thx
最佳答案
it is showing an error that myBean has no property 'complete'
属性(property)?此操作方法首先不应被视为属性。这表明#{myBean.complete}
被视为值表达式而不是方法表达式,就像您在纯 HTML 中内联它时所发生的情况一样 <p>#{myBean.complete}</p>
。这反过来表明<p:autoComplete>
标签根本不被识别为 JSF 组件,而只是被视为纯文本/HTML。这反过来表明 PrimeFaces taglib URI 错误,或者 JAR 文件未正确放置在 Web 应用程序的运行时类路径中。
确保您至少使用 PrimeFaces 3.0 版(在旧版本中,taglib URI 不同)并且 JAR 文件放置在 /WEB-INF/lib
中webapp 的文件夹。
关于java - Bean 无法通过 primefaces 识别该方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12172042/