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.

Rajat Gupta
  • 25,853
  • 63
  • 179
  • 294

2 Answers2

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>
Dave Mulligan
  • 1,623
  • 3
  • 19
  • 31
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) {  
    // ... 
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555