Listening to onSelect events from Autocomplete (Primefaces) component

[亡魂溺海] 提交于 2020-01-04 01:58:06

问题


I am trying to listen to select event from autocomplete using attribute selectListener. I am passing a remoteCommand as select listener. But the selectListener never calls this remoteCommand method.

My code follows:

<h:form>
    <p:autoComplete autocomplete="true" completeMethod="#{search.fetchSuggestions}" value="#{search.selectedSuggestion}" selectListener="moveToSelectedPage()"/>

    <p:remoteCommand name="moveToSelectedPage" action="firstPage.xhtml?faces-redirect=true" />
</h:form>

All I am trying to do is, navigating to a different page after the user selects a particular suggested item among suggestions made by autocomplete.


回答1:


The selectListener attribute should refer to a managed bean method taking SelectEvent and returning void, not to some arbitrary JavaScript function.

See also the PrimeFaces <p:autoComplete> showcase page.

<p:autoComplete selectListener="#{autoCompleteBean.handleSelect}" ... />  

with

public void handleSelect(SelectEvent event) {  
    // ... 
}



回答2:


Looking at PrimeFaces version 3.5, it appears that the selectListener attribute is no longer available for the AutoComplete component. The link in BalusC's answer leads to the correct place, where it shows the new approach to be to include a <p:ajax> tag inside the <p:autocomplete>:

<p:autoComplete id="acSimple" value="#{autoCompleteBean.txt1}" completeMethod="#{autoCompleteBean.complete}">  
  <p:ajax event="itemSelect" listener="#{autoCompleteBean.handleSelect}" update="messages" />  
</p:autoComplete>


来源:https://stackoverflow.com/questions/6635209/listening-to-onselect-events-from-autocomplete-primefaces-component

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!