我需要您的集体专业知识... (感谢您为我提供的任何指导!!)
问题: 我的 PrimeFaces“ p:autocomplete ”标签在“ completeMethod ”属性上生成“ Method not found ”错误……但是,这个方法显然存在于“ TestBean ”支持 bean 中!
问题: 错误的原因是什么?
(FWIW:使用这个标签似乎是一个相当直观的任务......起初。--但是,我显然从根本上误解了一些东西......我只是不知道是什么)。
这是错误消息...
WARNING: /index.xhtml @17,215 completeMethod="#{testBean.itemList}": Method not found: aaa.bbb.ccc.war.TestBean@13a494d.itemList(java.lang.String)
javax.el.MethodNotFoundException: /index.xhtml @17,215 completeMethod="#{testBean.itemList}": Method not found: aaa.bbb.ccc.war.TestBean@13a494d.itemList(java.lang.String)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:109)
at org.primefaces.component.autocomplete.AutoComplete.broadcast(AutoComplete.java:358)
这是包含 p:autocomplete 标记的 facelet 页面...
<?xml version='1.0' encoding='UTF-8' ?>
<!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:util="http://java.sun.com/jsf/composite/util"
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:c="http://java.sun.com/jsp/jstl/core"
xmlns:p="http://primefaces.org/ui">
<f:view contentType="text/html">
<h:head>
<title>testprimeac</title>
<meta charset="utf-8" />
</h:head>
<h:body>
<h:form id="form1">
<p:autoComplete id="abc" dropdown="true" value="#{testBean.item}" completeMethod="#{testBean.itemList}" var="item" itemLabel="#{item.itemLabel}" itemValue="#{item.itemValue}" forceSelection="true"></p:autoComplete>
</h:form>
</h:body>
</f:view>
</html>
这是包含有问题的方法的“TestBean”支持bean (或者我认为) ......
package aaa.bbb.ccc.war;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import javax.faces.context.FacesContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
@Component("testBean")
@Scope("request")
public class TestBean implements Serializable
{
public TestBean()
{
}
private static final Map<String, String> listBoxEntryMap;
static
{
Map<String, String> m = new LinkedHashMap<String, String>();
m.put("aaavalue", "aaalabel");
m.put("bbbvalue", "aablabel");
m.put("cccvalue", "abblabel");
m.put("dddvalue", "bbblabel");
m.put("eeevalue", "bbclabel");
m.put("fffvalue", "bcclabel");
m.put("gggvalue", "ccclabel");
m.put("hhhvalue", "ccalabel");
m.put("iiivalue", "caalabel");
m.put("jjjvalue", "aaclabel");
m.put("kkkvalue", "acclabel");
m.put("lllvalue", "bbalabel");
m.put("mmmvalue", "baalabel");
listBoxEntryMap = Collections.unmodifiableMap(m);
}
private Item item;
public Item getItem()
{
return this.item;
}
public void setItem(Item i)
{
this.item = i;
}
private static List<Item> itemList = new ArrayList<Item>();
public void setItemList(List<Item> data) throws IOException
{
itemList = (null==data?new ArrayList<Item>():data);
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("itemList",itemList);
}
public static List<Item> getItemList()
{
if (null==itemList)
{
try
{
if (FacesContext.getCurrentInstance().getExternalContext().getSessionMap().containsKey("itemList"))
{
itemList = (List<Item>) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("itemList");
}
if (null == itemList || itemList.isEmpty())
{
itemList = getListOfItems();
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("itemList",itemList);
}
return itemList; //(list);
}
catch (Exception ex)
{
java.util.logging.Logger.getLogger(TestBean.class.getName()).log(Level.SEVERE, null, ex);
}
}
return itemList;
}
public static List<Item> getItemList(String s)
{
itemList = getItemList();
List<Item> suggestions = new ArrayList<Item>();
for (Item i : itemList)
{
if (i.getItemLabel().startsWith(s))
{
suggestions.add(i);
}
}
return suggestions;
}
public static List<Item> getListOfItems()
{
List<Item> list = null;
try
{
Map<String, String> map = listBoxEntryMap;
Iterator iter = map.keySet().iterator();
list = new ArrayList<Item>();
while (iter.hasNext())
{
String key = (String) iter.next();
String val = (String) map.get(key);
list.add(new Item(key,val));
}
}
catch (Exception e)
{
System.out.println("Exception during query call..." + e.getMessage());
e.printStackTrace();
}
return (null==list?new ArrayList<Item>():list);
}
}
这是与自动完成一起使用的“项目”pojo 类 *(值和标签都是字符串,我认为这意味着不需要“转换器”类)
package aaa.bbb.ccc.war;
public class Item
{
public Item()
{
}
public Item(String l, String v)
{
this.itemLabel = (null == l ? "" : l);
this.itemValue = (null == v ? "" : v);
}
private String itemLabel = "";
private String itemValue = "";
@Override
public String toString()
{
return (null == this.itemValue ? "" : this.itemValue);
}
public String getString()
{
return (null == this.itemValue ? "" : this.itemValue);
}
public String getItemLabel()
{
return (null == this.itemLabel ? "" : this.itemLabel);
}
public void setItemLabel(String s)
{
this.itemLabel = s;
}
public String getItemValue()
{
return (null == this.itemValue ? "" : this.itemValue);
}
public void setItemValue(String s)
{
this.itemValue = s;
}
}
FWIW - 这是构建 pom.xml,用于查看使用的依赖项/版本...
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>aaa.bbb.ccc</groupId>
<artifactId>testprimeac-war</artifactId>
<packaging>war</packaging>
<version>1</version>
<name>testprimeac-war</name>
<url>http://maven.apache.org</url>
<properties>
<org.springframework-version>3.1.1.RELEASE</org.springframework-version>
<jsf-version>2.1.11</jsf-version>
</properties>
<dependencies>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1.11</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.1.11</version>
</dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>el-api</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>el-impl</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>3.4.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
</plugin>
</plugins>
<finalName>testprimeac-${project.version}</finalName>
</build>
</project>