Primefaces自动完成构件收到错误:属性“标签”上java.lang.String类型未发现 [英] Primefaces autocomplete widget getting error: Property 'label' not found on type java.lang.String

查看:260
本文介绍了Primefaces自动完成构件收到错误:属性“标签”上java.lang.String类型未发现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法顺利拿到P:自动完成窗口小部件的工作...

使用自动完成构件,如下所示...

 <电话号码:自动完成ID =ABC下拉菜单=真值=#{testBean.parmMap ['inputval']}completeMethod =#{testBean.testList }VAR =项目itemLabel =#{} items.labelitemValue =#{}项目转换器=#{} itemConverter>< / p:自动完成>

我收到以下错误消息...


  

javax.el.PropertyNotFoundException:/index.xhtml @ 18245 itemLabel =#{} items.label:属性标签上java.lang.String类型未发现


我一直没能闯过此错误。不能确定问题所在
--I've包括最下图所示的相关code的。谢谢你的任何指导,你能提供给我!

这里是整个Facelets页面 - ...的index.xhtml

 < XML版本='1.0'编码='UTF-8'&GT?;
!< D​​OCTYPE HTML PUBLIC - // W3C // DTD XHTML 1.0过渡// ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
< HTML的xmlns =htt​​p://www.w3.org/1999/xhtml
      的xmlns:UTIL =htt​​p://java.sun.com/jsf/composite/util
      的xmlns:UI =htt​​p://java.sun.com/jsf/facelets
      的xmlns:H =htt​​p://java.sun.com/jsf/html
      的xmlns:F =htt​​p://java.sun.com/jsf/core
      的xmlns:C =htt​​p://java.sun.com/jsp/jstl/core
      的xmlns:P =htt​​p://primefaces.org/ui>
    < F:视图的contentType =text / html的>
        < H:头>
            <标题> testprimeac< /标题>
            <间的charset =UTF-8/>
        < /小时:头>
        < H:身体GT;
            < H:表ID =form1的>
                <电话号码:自动完成ID =ABC下拉菜单=真值=#{testBean.parmMap ['inputval']}completeMethod =#{} testBean.testListVAR =项目itemLabel =#{ items.label}itemValue =#{}项目转换器=#{} itemConverter>< / p:自动完成>
            < /小时:形式>
        < /小时:身体GT;
    < / F:视图>
< / HTML>`

这里是项级...


    包aaa.bbb.ccc.war;

 公共类项目
{    私人字符串标签;
    私人字符串值;    公共字符串getLabel()
    {
        返回标签;
    }    公共无效setLabel(字符串标签)
    {
        this.label =标签;
    }    公共字符串的getValue()
    {
        返回值;
    }    公共无效的setValue(字符串值)
    {
        THIS.VALUE =价值;
    }
}

这里是ItemConverter类...

    包aaa.bbb.ccc.war;

 进口的java.util.List;
进口javax.faces.application.FacesMessage;
进口javax.faces.component.UIComponent;
进口javax.faces.context.FacesContext;
进口javax.faces.convert.Converter接口;
进口javax.faces.convert.ConverterException;公共类ItemConverter实现转换器
{    @覆盖
    公共对象的getAsObject(FacesContext中的FacesContext,UIComponent组件,字符串submittedValue中)
    {
        如果(submittedValue.trim()。等于())
        {
            返回null;
        }
        其他
        {
            ITEMLIST = getItemList();            尝试
            {
                对于(项目编号:ITEMLIST)
                {
                    如果(item.getValue()。equalsIgnoreCase(submittedValue中))
                    {
                        归还物品;
                    }
                }            }
            赶上(例外五)
            {
                抛出新的ConverterException(新的FacesMessage(FacesMessage.SEVERITY_ERROR,转换错误,不是一个有效的项目对象))​​;
            }
        }        返回null;
    }    @覆盖
    公共字符串符getAsString(FacesContext中的FacesContext,UIComponent组件,对象的值)
    {
        如果(价值== NULL || value.equals())
        {
            返回;
        }
        其他
        {
            返回将String.valueOf(((项目)值).getValue());
        }
    }
    私人静态列表<项目> ITEMLIST;    私人静态列表<项目> getItemList()
    {
        如果(空== ITEMLIST)
        {
            refData = getRefData();
            ITEMLIST = refData.getTestList();
        }        返回ITEMLIST;
    }
    私有静态RefData refData;    私有静态RefData getRefData()
    {
        refData =(RefData)FacesContext.getCurrentInstance()getExternalContext()getSessionMap()获得(refData)。;
        如果(空== refData)
        {
            refData =新RefData();
            。FacesContext.getCurrentInstance()getExternalContext()getSessionMap()把(refData,refData)。
        }
        返回refData;
    }
}

这里是中,testBean类...

    包aaa.bbb.ccc.war;

 的Bean;
进口java.util.LinkedHashMap中;
进口的java.util.List;
进口的java.util.Map;
进口javax.faces.context.FacesContext;
进口org.springframework.context.annotation.Scope;
进口org.springframework.stereotype.Component;@Component(testBean这个)
@Scope(请求)
公共类testBean就实现Serializable
{    私人RefData refData;
    私人LinkedHashMap的<字符串,字符串> parmMap;    公共testBean这个()
    {
    }    公共地图<字符串,字符串> getParmMap()
    {
        refData = getRefData();
        返回refData.getParmMap();
    }    公共无效setParmMap(LinkedHashMap的<字符串,字符串> M)
    {
        refData = getRefData();
        refData.setParmMap(米);
        storeRefData(refData);
    }    公共无效setTestList(列表<项目>列表)抛出异常
    {
        尝试
        {
            refData = getRefData();
            refData.setTestList(名单);
            storeRefData(refData);
        }
        赶上(例外五)
        {
            e.printStackTrace();
        }
    }    公开名单<项目> getTestList()
    {
        refData = getRefData();
        返回refData.getTestList();
    }    私有静态RefData getRefData()
    {
        RefData refData =(RefData)FacesContext.getCurrentInstance()getExternalContext()getSessionMap()获得(refData)。;
        如果(空== refData)
        {
            refData =新RefData();
            。FacesContext.getCurrentInstance()getExternalContext()getSessionMap()把(refData,refData)。
        }
        返回refData;
    }    私有静态无效storeRefData(RefData R)
    {
        。FacesContext.getCurrentInstance()getExternalContext()getSessionMap()把(refData,R)。
    }
}

这里是RefData类(在testBean这个简称)...

    包aaa.bbb.ccc.war;

 进口java.io.IOException异常;
的Bean;
进口的java.util.ArrayList;
进口java.util.Arrays中;
进口java.util.Collections中;
进口的java.util.HashMap;
进口java.util.Iterator的;
进口java.util.LinkedHashMap中;
进口的java.util.List;
进口的java.util.Map;
进口java.util.logging.Level中;公共类RefData实现Serializable
{    公共RefData()//(字符串键)
    {
    }
    私有静态最终地图<字符串,字符串> listBoxEntryMap;    静态的
    {
        地图<字符串,字符串> M =新的LinkedHashMap<字符串,字符串>();
        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(iii​​value,caalabel);
        m.put(jjjvalue,aaclabel);
        m.put(kkkvalue,acclabel);
        m.put(lllvalue,bbalabel);
        m.put(mmmvalue,baalabel);        listBoxEntryMap = Collections.unmodifiableMap(米);
    }
    私人地图<字符串,字符串> parmMap;    公共地图getParmMap()
    {
        如果(空== this.parmMap)
        {
            this.parmMap =新的LinkedHashMap<字符串,字符串>();
            this.parmMap.put(inputval,);
        }        返回this.parmMap;
    }    公共无效setParmMap(图M)
    {
        this.parmMap =米;
    }
    清单<项目> testList =新的ArrayList<项目>();    公共无效setTestList(列表<项目>数据)抛出IOException异常
    {
        testList =数据;
    }    公开名单<项目> getTestList()
    {
        尝试
        {
            如果(空== testList || testList.isEmpty())
            {
                testList = getListOfItems();
            }            返回testList; //(名单);
        }
        赶上(异常前)
        {
            。java.util.logging.Logger.getLogger(RefData.class.getName())日志(Level.SEVERE,空,前);
        }        返回null;
    }    公共静态列表<项目> getListOfItems()
    {
        清单<项目>名单= NULL;
        尝试
        {
            地图<字符串,字符串>地图= listBoxEntryMap;
            。迭代器ITER = map.keySet()迭代器();            名单=新的ArrayList<项目>();
            项目项目= NULL;            而(iter.hasNext())
            {
                字符串键=(字符串)iter.next();
                字符串VAL =(字符串)map.get(密钥);
                项目=新的项目();
                item.setLabel(键);
                item.setValue(VAL);
                list.add(项目);
            }
        }
        赶上(例外五)
        {
            的System.out.println(查询通话过程中的异常...+ e.getMessage());
            e.printStackTrace();
        }        返回列表;
    }
}

FWIW - 这里是pom.xml中(其中包括primefaces依赖)...

 <项目的xmlns =htt​​p://maven.apache.org/POM/4.0.0的xmlns:XSI =htt​​p://www.w3.org/2001 / XML模式实例
         XSI:的schemaLocation =htt​​p://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd\">
    < modelVersion> 4.0.0< / modelVersion>
    <&的groupId GT; aaa.bbb.ccc< /的groupId>
    <&的artifactId GT; testprimeac战< / artifactId的>
    <包装和GT;战争与LT; /包装>
    <&版GT; 1 LT; /版本>
    <名称> testprimeac战< /名称>
    &LT; URL&GT; HTTP://maven.apache.org< / URL&GT;
    &LT;性状&gt;
        &LT; org.springframework版本&GT; 3.1.1.RELEASE&LT; /org.springframework-version>
        &LT; JSF的版本&GT; 2.1.11&LT; / JSF版本&GT;
    &LT; /性状&gt;
    &LT;依赖和GT;
        &LT;&依赖性GT;
            &LT;&的groupId GT;公共郎&LT; /的groupId&GT;
            &LT;&的artifactId GT;公共郎&LT; / artifactId的&GT;
            &LT;&版GT; 2.6&LT; /版本&GT;
        &LT; /依赖性&GT;
        &LT;&依赖性GT;
            &LT;&的groupId GT;的javax.servlet&LT; /的groupId&GT;
            &LT;&的artifactId GT;的servlet-API&LT; / artifactId的&GT;
            &LT;&版GT; 2.5 LT; /版本&GT;
            &LT;&范围GT;及提供LT; /&范围GT;
        &LT; /依赖性&GT;
        &LT;&依赖性GT;
            &LT;&的groupId GT;的javax.servlet&LT; /的groupId&GT;
            &LT;&的artifactId GT;&JSTL LT; / artifactId的&GT;
            &LT;&版GT; 1.2 LT; /版本&GT;
        &LT; /依赖性&GT;
        &LT;&依赖性GT;
            &LT;&的groupId GT; com.sun.faces&LT; /的groupId&GT;
            &LT;&的artifactId GT;与JSF API&LT; / artifactId的&GT;
            &LT;&版GT; 2.1.11&LT; /版本&GT;
        &LT; /依赖性&GT;
        &LT;&依赖性GT;
            &LT;&的groupId GT; com.sun.faces&LT; /的groupId&GT;
            &LT;&的artifactId GT; JSF-implement执行&LT; / artifactId的&GT;
            &LT;&版GT; 2.1.11&LT; /版本&GT;
        &LT; /依赖性&GT;
        &LT;&依赖性GT;
            &LT;&的groupId GT; javax.el&LT; /的groupId&GT;
            &LT;&的artifactId GT; EL-API&LT; / artifactId的&GT;
            &LT;&版GT; 2.2&LT; /版本&GT;
        &LT; /依赖性&GT;
        &LT;&依赖性GT;
            &LT;&的groupId GT; org.glassfish.web&LT; /的groupId&GT;
            &LT;&的artifactId GT; EL-implement执行&LT; / artifactId的&GT;
            &LT;&版GT; 2.2&LT; /版本&GT;
        &LT; /依赖性&GT;
        &LT;&依赖性GT;
            &LT;&的groupId GT; org.springframework&LT; /的groupId&GT;
            &LT;&的artifactId GT;春上下文&LT; / artifactId的&GT;
            &LT;&版GT; $ {org.springframework版本}&LT; /版本&GT;
        &LT; /依赖性&GT;
        &LT;&依赖性GT;
            &LT;&的groupId GT; org.springframework&LT; /的groupId&GT;
            &LT;&的artifactId GT;弹簧webmvc&LT; / artifactId的&GT;
            &LT;&版GT; $ {org.springframework版本}&LT; /版本&GT;
        &LT; /依赖性&GT;
        &LT;&依赖性GT;
            &LT;&的groupId GT; org.primefaces&LT; /的groupId&GT;
            &LT;&的artifactId GT; primefaces&LT; / artifactId的&GT;
            &LT;&版GT; 3.4.2&LT; /版本&GT;
        &LT; /依赖性&GT;
    &LT; /依赖和GT;
    &LT;建立&GT;
        &LT;&插件GT;
            &LT;&插件GT;
                &LT;&的groupId GT; org.apache.maven.plugins&LT; /的groupId&GT;
                &LT;&的artifactId GT; Maven的编译器插件&LT; / artifactId的&GT;
                &LT;结构&gt;
                    &lt;信源&GT; 1.6 LT; /源&GT;
                    &lt;目标&GT; 1.6 LT; /目标与GT;
                &LT; /结构&gt;
            &LT; /插件&GT;
            &LT;&插件GT;
                &LT;&的groupId GT; org.apache.maven.plugins&LT; /的groupId&GT;
                &LT;&的artifactId GT; Maven的战争插件&LT; / artifactId的&GT;
                &LT;&版GT; 2.3&LT; /版本&GT;
            &LT; /插件&GT;
        &LT; /插件&GT;
        &LT; finalName&GT; testprimeac - $ {project.version}&LT; / finalName&GT;
    &LT; /构建&GT;
&LT; /项目&GT;


解决方案

+1为您在第一款所作的断言:你对这里太多的信息,并因为你绑定到一个基本的转换是不必要的字符串键入

我在这里看到的两个主要问题是


  1. 您的选择不在你的值绑定使用类型安全的集合。使用纯的LinkedHashMap 持有字符串值很可能导致问题,因为它们将被存储为对象,我不认为编译有义务在这里做任何自动装箱为你。


  2. 您的支持 completeMethod 的实施实质上是returninglkp 字符串对象的商店。这就是为 VAR 在自动完成的变量。不言自明的,你不能叫 getLabel()这一点。


您可以继续任2种方式


  1. 更​​改您的数据存储到字符串类型安全的LinkedList ,失去了转换器和你应该罚款。你的 VAR 是纯项目 itemLabel itemValue 都将是#{项目}


  2. 实现一个POJO封装的选择对象,保持转换器,然后你的后备数据存储成为你的POJO的简单列表,并选择成为POJO,而不是一个String的实例


编辑:有了您的澄清,问题是由自动完成下拉菜单的返回类型的差异的结果(类型项目)和自动完成,以支持bean(字符串键入)的结合。通过下拉菜单选择返回的类型必须是一样的,你会在后台bean结合的类型。

I am unable to successfully get the "p:autocomplete" widget to work...

Using the autocomplete widget, as shown here...

<p:autoComplete id="abc"  dropdown="true" value="#{testBean.parmMap['inputval']}" completeMethod="#{testBean.testList}" var="items" itemLabel="#{items.label}" itemValue="#{items}" converter="#{itemConverter}" ></p:autoComplete>

I am receiving the following error message...

javax.el.PropertyNotFoundException: /index.xhtml @18,245 itemLabel="#{items.label}": Property 'label' not found on type java.lang.String

I have not been able to get past this error. Not certain where the problem lies --I've included most of the relevant code shown below. Thank you for any guidance you can provide me!

Here is the entire facelets page - index.xhtml...

<?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.parmMap['inputval']}" completeMethod="#{testBean.testList}" var="items" itemLabel="#{items.label}" itemValue="#{items}" converter="#{itemConverter}" ></p:autoComplete>
            </h:form>
        </h:body>
    </f:view>
</html>`

Here is the "Item" class...

package aaa.bbb.ccc.war;

public class Item
{

    private String label;
    private String value;

    public String getLabel()
    {
        return label;
    }

    public void setLabel(String label)
    {
        this.label = label;
    }

    public String getValue()
    {
        return value;
    }

    public void setValue(String value)
    {
        this.value = value;
    }
}

Here is the ItemConverter class... package aaa.bbb.ccc.war;

import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;

public class ItemConverter implements Converter
{

    @Override
    public Object getAsObject(FacesContext facesContext, UIComponent component, String submittedValue)
    {
        if (submittedValue.trim().equals(""))
        {
            return null;
        }
        else
        {
            itemList = getItemList();

            try
            {
                for (Item item : itemList)
                {
                    if (item.getValue().equalsIgnoreCase(submittedValue))
                    {
                        return item;
                    }
                }

            }
            catch (Exception e)
            {
                throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Conversion Error", "Not a valid item object"));
            }
        }

        return null;
    }

    @Override
    public String getAsString(FacesContext facesContext, UIComponent component, Object value)
    {
        if (value == null || value.equals(""))
        {
            return "";
        }
        else
        {
            return String.valueOf(((Item) value).getValue());
        }
    }
    private static List<Item> itemList;

    private static List<Item> getItemList()
    {
        if (null == itemList)
        {
            refData = getRefData();
            itemList = refData.getTestList();
        }

        return itemList;
    }
    private static RefData refData;

    private static RefData getRefData()
    {
        refData = (RefData) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("refData");
        if (null == refData)
        {
            refData = new RefData();
            FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("refData", refData);
        }
        return refData;
    }
}

Here is the TestBean class... package aaa.bbb.ccc.war;

import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
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
{

    private RefData refData;
    private LinkedHashMap<String, String> parmMap;

    public TestBean()
    {
    }

    public Map<String, String> getParmMap()
    {
        refData = getRefData();
        return refData.getParmMap();
    }

    public void setParmMap(LinkedHashMap<String, String> m)
    {
        refData = getRefData();
        refData.setParmMap(m);
        storeRefData(refData);
    }

    public void setTestList(List<Item> list) throws Exception
    {
        try
        {
            refData = getRefData();
            refData.setTestList(list);
            storeRefData(refData);
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    public List<Item> getTestList()
    {
        refData = getRefData();
        return refData.getTestList();
    }

    private static RefData getRefData()
    {
        RefData refData = (RefData) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("refData");
        if (null == refData)
        {
            refData = new RefData();
            FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("refData", refData);
        }
        return refData;
    }

    private static void storeRefData(RefData r)
    {
        FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("refData", r);
    }
}

Here is the RefData class (referred to in TestBean)... package aaa.bbb.ccc.war;

import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;

public class RefData implements Serializable
{

    public RefData() //(String key)
    {
    }
    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 Map<String, String> parmMap;

    public Map getParmMap()
    {
        if (null == this.parmMap)
        {
            this.parmMap = new LinkedHashMap<String, String>();
            this.parmMap.put("inputval", "");
        }

        return this.parmMap;
    }

    public void setParmMap(Map m)
    {
        this.parmMap = m;
    }
    List<Item> testList = new ArrayList<Item>();

    public void setTestList(List<Item> data) throws IOException
    {
        testList = data;
    }

    public List<Item> getTestList()
    {
        try
        {
            if (null == testList || testList.isEmpty())
            {
                testList = getListOfItems();
            }

            return testList; //(list);
        }
        catch (Exception ex)
        {
            java.util.logging.Logger.getLogger(RefData.class.getName()).log(Level.SEVERE, null, ex);
        }

        return null;
    }

    public static List<Item> getListOfItems()
    {
        List<Item> list = null;
        try
        {
            Map<String, String> map = listBoxEntryMap;
            Iterator iter = map.keySet().iterator();

            list = new ArrayList<Item>();
            Item item = null;

            while (iter.hasNext())
            {
                String key = (String) iter.next();
                String val = (String) map.get(key);
                item = new Item();
                item.setLabel(key);
                item.setValue(val);
                list.add(item);
            }
        }
        catch (Exception e)
        {
            System.out.println("Exception during query call..." + e.getMessage());
            e.printStackTrace();
        }

        return list;
    }
}

FWIW - Here is the pom.xml (which includes the primefaces dependency)...

<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>

解决方案

+1 for the assertions you made in your first paragraph: You do have too much information on here and the converter is unnecessary since you're binding to a basic String type.

The two main issues I see here Are

  1. your choice to not use a type-safe collection in your value binding. Using a plain LinkedHashMap to hold String values will most likely cause problems as they will be stored as objects, I don't think the compiler is obliged to do any autoboxing for you here.

  2. Your backing completeMethod implementation is essentially returninglkp a store of String objects. This is what provides the variable for var in the autocomplete . To state the obvious, you can't call getLabel() on that.

You can proceed either of 2 ways

  1. Change your data store to a typesafe LinkedList of Strings , Lose the converter and you should be fine. Your var will be plain item and itemLabel and itemValue will both be #{item}.

  2. Implement a POJO to encapsulate the selection object, keep the converter and then your backing data store becomes a simple list of your POJO and also your selection becomes an instance of the POJO instead of a String

EDIT: With your clarifications, the problem is as a result of the discrepancy in the type returned by the autocomplete dropdown (Type item) and the value binding of the autocomplete to the backing bean (String type). The type returned by the dropdown selection must be the same as the type you're binding to in the backing bean.

这篇关于Primefaces自动完成构件收到错误:属性“标签”上java.lang.String类型未发现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆