这是primefaces自动完成中的错误吗? [英] Is this a bug in primefaces autocomplete?

查看:50
本文介绍了这是primefaces自动完成中的错误吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试放置一个自动完成功能,该功能可将建议作为Entry<String, Integer>

I'm trying to put an autocomplete that fetches suggestions as a list of Entry<String, Integer>

<p:autoComplete completeMethod="#{suggester.suggestTopics}"
            var="x1" itemLabel="#{x1.key}" itemValue="#{x1.value.toString()}" 
            value="#{topicController.selected}"   />

受管理的bean代码如下:

Manged bean code is as follows:

private int selected;

public int getSelected() {
    return selected;
}

public void setSelected(int selected) {
    this.selected= selected;
}

但是这不能说Integer类没有名为key的方法/属性.如果我从自动完成功能中删除了value属性,那么它将开始正常工作.但是,当我放置value属性时,它开始期望var内部的对象应该与value属性内部的对象具有相同的类型.我相信/期望应该是itemValue内部的对象应该与value属性内部的对象具有相同的类型.

But this fails saying the Integer class doesn't have method/property named key. If I remove the value attribute from autocomplete then it starts working properly. But when I put value attribute it starts expecting that the object inside var should be of the same type as that inside value attribute. I believe/expect it should be that the object inside itemValue should be of the same type as that inside value attribute.

我想使用POJO进行建议,但只将实体ID传递给值

使用: Primefaces 3.1 JSF 2.1.6

Using : Primefaces 3.1 JSF 2.1.6

推荐答案

我认为/期望应该是itemValue内的对象应该 与内部值属性的类型相同.

I believe/expect it should be that the object inside itemValue should be of the same type as that inside value attribute.

是的,这是有道理的,并且在 primefaces展示柜中也是如此:

Yes this makes sense, and it is the same in the primefaces showcase:

<p:autoComplete value="#{autoCompleteBean.selectedPlayer1}" 
                id="basicPojo" 
                completeMethod="#{autoCompleteBean.completePlayer}"  
                var="p" itemLabel="#{p.name}" itemValue="#{p}" 
                converter="player" forceSelection="true"/>  

如您所见,

var="p"itemValue="#{p},其中p是Player的实例.而且selectedPlayer1也是Player的实例.

As you see is var="p" and itemValue="#{p} where p is an instance of Player. And selectedPlayer1 is also an instance of Player.

我不知道它是否可以与Map一起使用,因为Primefaces示例被称为"Pojo支持",建议应该是与value属性中相同类型的元素的List.

I don't know if it works with a Map since the Primefaces example is called "Pojo support" and the suggestions should be a List of elements of the same type as in the value attribute.

这篇关于这是primefaces自动完成中的错误吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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