开发者

Listening to onSelect events from Autocomplete (Primefaces) component

开发者 https://www.devze.com 2023-03-18 21:56 出处:网络
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.

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 fo开发者_运维百科llows:

<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.


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>


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) {  
    // ... 
}
0

精彩评论

暂无评论...
验证码 换一张
取 消