【发布时间】:2016-01-03 04:31:00
【问题描述】:
我需要一个带有字符串值的自动完成,因为用户不能通过自动完成方法限制提供的项目,但他们应该能够在搜索字段中写入任何内容。如果他们愿意,他们也可以从建议中进行选择。
现在我总是得到 /archive/overview.xhtml @28,57 itemLabel="#{item.name}":类'java.lang.String'没有属性'name'。
XHTML:
<p:autoComplete id="vyraz" value="#{archiveView.searchString}"
completeMethod="#{archiveView.autocomplete}"
var="item" itemLabel="#{item.name}" itemValue="#{item.name}"
converter="archiveConverter" forceSelection="false" minQueryLength="2"
autoHighlight="false" effect="fade">
<p:column>
<h:outputText value="#{item.name}"/>
<h:outputText value=" (Barcode: #{item.barcode})" rendered="#{item.barcode ne null}"/>
</p:column>
<p:column>
<h:outputText value="#{item.type.label}" style="font-weight: bold;"/>
</p:column>
</p:autoComplete>
豆子:
private String searchString; // + getter and setter
public List<ArchiveAutoCompleteDto> autocomplete(String query) {
// get and return from lucene index/database
}
有没有办法实现这个(Primefaces 5.2)?
谢谢!
【问题讨论】:
-
我已经解决了移除转换器并使用以下标签/值的问题: itemLabel="#{item.class.simpleName eq 'String' ? item : item.name}" itemValue=" #{item.class.simpleName eq 'String' ? item : item.name}"
标签: jsf jsf-2 primefaces autocomplete converter