3

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.

2 Answers 2

9

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>
0
8

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.