问题描述
我有一个具有maxResult
和moreText
属性的自动完成功能.
I have a autocomplete with a maxResult
and a moreText
property.
XHTML
<p:autoComplete maxResults="50" moreText="show more results" ...>
<p:ajax event="moreText" listener="#{bean.onMoreText} />
</p:autoComplete
Bean
public void onMoreText(AjaxBehaviourEvent event) {
AutoComplete ac = (AutoComplete)event.getSource();
ac.setMaxResults(ac.getMaxResults() + 50);
}
我想要的是结果列表扩展了另外50行.它确实可以这种方式工作,但是我的问题是,单击moreText
行后,结果列表将隐藏.当我再次搜索时,将得到一个包含100、150,...个结果的结果列表.
What I want is that the result list expands for additional 50 rows. It does work this way but my the problem is that the result list hides after click on the moreText
row. When I search again I'll get a result list with 100, 150, ... results.
如何在单击show more results
推荐答案
我通过添加以下代码找到了适合我需求的解决方案
I found a solution which fits my needs by adding this code
<p:autoComplete widgetVar="widgetVarName" completeMethod="#{bean.complete}">
<p:ajax event="moreText" listener="#{bean.onMoreText}" />
</p:autoComplete>
public List<ResultType> complete(String qry) {
setQryString(qry);
// code to get results;
}
public void onMoreText(javax.faces.event.AjaxBehaviorEvent event) {
org.primefaces.component.autocomplete.AutoComplete ac = (AutoComplete) event.getSource();
ac.setMaxResults(ac.getMaxResults() + 30);
executeJS("PF('widgetVarName').search('" + getQryString() + "')");
}
public void executeJS(String source) {
org.primefaces.context.RequestContext.getCurrentInstance().execute(source);
}
现在发生的事情是,在您单击moreText行之后,会建议列表隐藏起来,maxResults会增加,并且新搜索将从用于completeMethod的qryString开始.
What is happening now is that after you click on the moreText row the suggestionList hides, maxResults gets increased and a new search starts with the qryString used for the completeMethod.
如果有人有更好的解决方案,请随时与我们分享,因为我当前的解决方案是一种糟糕的解决方法,它会为已传输的数据调用新的数据库选择.
If someone has a better solution feel free to share it with us because my current solution is a terrible workaround which invokes a new database select for data that were already transferred.
这篇关于PrimeFaces autoComplete使用moreText扩展maxResults的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!