PrimeFaces P:自动完成不转换在ArrayList中
我正在从 RichFaces 转换为 PrimeFaces 11.0,并用 p:autoComplete 替换基于旧的 rich:suggestionBox 的自定义组件。这在大多数值引用 POJO 属性的代码中都非常有效。然而,我发现很难让 p:autoComplete 设置 POJO ArrayList 的引用值。
class OrderItem {
...
public List<Contact> getContacts() {
return contacts;
}
...
}
在视图上,我们希望能够允许对每个 orderItem 的多个联系人进行自动完成。 orderItem.contacts 列表在呈现时已预先填充了空占位符:
<ui:repeat id="assignabilityContacts" value="#{orderItem.contacts}" var="_contact" varStatus="idx">
...
<p:autoComplete value="#{orderItem.contacts[idx.index]}"
id="existingContact"
binding="#{contactGroupManager.contactAutoComplete}"
converter="#{baseEntityConverter}"
completeMethod="#{contactGroupManager.autocomplete}"
forceSelection="true"
var="row" itemValue="#{row}" itemLabel="#{row.toString()}"
minQueryLength="2"
maxResults="10"
>
<f:attribute name="orderItem" value="#{orderItem}" />
</p:autoComplete>
完整方法的签名是...
public List<Contact> autocomplete(Object suggest) {
}
并且转换器遵循实体的 Bauke Scholtz 模式: 为具有 Java 泛型的实体实现转换器
如上所定义, orderItem.contacts[idx.index] 被设置为一个字符串,对应于所选 pojo 的 toString() 。转换器永远不会被调用。
如果我将该值更改为另一个支持 bean 上的 Contact 类的属性,则会调用转换器并将该属性设置为选定的 Contact 实体。这是正确的行为。
value="#{contactSelector.selectedContact}"
autoConverter 是否有可能没有从列表中选取实体类,是否有任何建议的解决方法?
I'm converting from RichFaces to PrimeFaces 11.0 and replacing a custom component based on the old rich:suggestionBox with p:autoComplete. This works perfectly in most code where the value refers to a POJO property. However I'm finding difficulty getting p:autoComplete to set the value of a reference from an ArrayList of POJOs.
class OrderItem {
...
public List<Contact> getContacts() {
return contacts;
}
...
}
On a view, we want to be able to allow autoCompletes on multiple contacts per orderItem. The orderItem.contacts list is prepopulated with null placeholders by the time this is rendered:
<ui:repeat id="assignabilityContacts" value="#{orderItem.contacts}" var="_contact" varStatus="idx">
...
<p:autoComplete value="#{orderItem.contacts[idx.index]}"
id="existingContact"
binding="#{contactGroupManager.contactAutoComplete}"
converter="#{baseEntityConverter}"
completeMethod="#{contactGroupManager.autocomplete}"
forceSelection="true"
var="row" itemValue="#{row}" itemLabel="#{row.toString()}"
minQueryLength="2"
maxResults="10"
>
<f:attribute name="orderItem" value="#{orderItem}" />
</p:autoComplete>
The signature of the complete method is...
public List<Contact> autocomplete(Object suggest) {
}
And the converter follows Bauke Scholtz pattern for entities:
Implement converters for entities with Java Generics
As defined above, the value of orderItem.contacts[idx.index] is being set to a string, corresponding to the toString() of the selected pojo. The converter is never called.
If I change the value to a property of class Contact on another backing bean, the converter is called and the property is set to the selected Contact entity. This is the correct behavior.
value="#{contactSelector.selectedContact}"
Is it possible that autoConverter is not picking up the entity class from the List, and are there any suggested workarounds for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论