这是primefaces自动完成中的错误吗? [英] Is this a bug in primefaces autocomplete?
问题描述
我正在尝试放置一个自动完成功能,该功能可将建议作为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屋!