p:ajax just to trigger js on itemSelect with autocomplete ?

UI Components for JSF
Post Reply
Aditya
Posts: 163
Joined: 16 Nov 2011, 20:19

21 Apr 2012, 18:38

I need to trigger a javascript method whenever one of the items/options suggested by autocomplete is selected(clicked). After realizing that onselect attribute is not meant for that purpose. I found another solution to use p:ajax like this :

Code: Select all

<p:autoComplete .....  >
                <p:ajax event="itemSelect" onstart="handleAutocompleteItemSelect();"/>
            </p:autoComplete>
But p:ajax is meant to be used for ajax operations, right ? So using it this way, is it recommended or are there any better ways to do this ?
*****
Aditya

Using :
Primefaces 5.0 + Omnifaces 1.7 + Prettyfaces
JSF 2.2.2 -Myfaces
Tomcat 7.0.42

tandraschko
PrimeFaces Core Developer
Posts: 3979
Joined: 03 Dec 2010, 14:11
Location: Bavaria, DE
Contact:

22 Apr 2012, 01:18

The better way is pe:javascript: http://fractalsoft.net/primeext-showcas ... aviour.jsf
You can use it like p:ajax but it only execute your custom JS. You can't use this for every component and event.
For example, datatable paginate required AJAX to get the new data.
Thomas Andraschko

PrimeFaces | PrimeFaces Extensions

Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE

Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 37 guests