Datatable how to register clientside only behaviour?

UI Components for JSF
9902468
Posts: 14
Joined: 14 Apr 2011, 07:45

18 Jul 2011, 16:35

Hi,

tried to google and search the forums for this, but really can't understand. We need to attach event listener to the datatable's onRowSelected event. This can be achieved using:

<p:ajax event="rowSelect" onstart="myJavascriptThingToRun();" />

But this does a submit that is not needed. How can I prevent the submit and just run the JS when user has selected a row?

- Ville
Ps. We're using 3.0.M2. Also, I tried this: http://primefaces.prime.com.tr/forum/vi ... f=3&t=1373, but the widget does not have function subscribe.

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

18 Jul 2011, 16:38

Code: Select all

<p:ajax event="rowSelect" onstart="myJavascriptThingToRun();return false;" />

9902468
Posts: 14
Joined: 14 Apr 2011, 07:45

18 Jul 2011, 17:40

Thanks!

Maybe I have had enough coffee today, as that just didn't cross my mind, but is painfully obvious now :)

- Ville

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

18 Jul 2011, 18:15

One problem I don't really like - onlick has the entire bunch of not necessary code after return false; Something like PrimeFaces.ab({formId:'j_idt43',source:'j_idt43:j_idt50',process:'@all',update:'j_idt43:panel ...

We need something to attach only client side callbacks without "dirty" code.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

19 Jul 2011, 21:22

Cagatay, what do you think about a new behavior for client-side callbacks (handlers) without ajax calls? I mean e.g.

Code: Select all

<p:command event="rowSelect" handler="myJavascriptThingToRun()" />
which doesn't generate Ajax stuff like p:ajax. We don't need onstart, oncomplete, etc. then in p:command. I have a lot of use cases where no ajax calls are needed, but at the moment ajax code is always generated in markup. The generated code will be cleaner and we could add more fancy attributes to p:command which are quite usefull (doesn't make sense to add them to p:ajax).

Not sure about name, maybe p:handler or p:callback sounds better.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

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

19 Jul 2011, 21:51

+1
but "before" and "after" handler methods would be great
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

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

19 Jul 2011, 23:06

Can we not write

Code: Select all

<p:command event="rowSelect" handler="myBeforeFunction(); myJavascriptThingToRun(); myAfterFunction();" />
? :-)

By the way, we have much more events for p:command than for a:ajax. We can use all possible jQuery events. At the moment I'm wondering how I can register onclick event on any datatable row in order to show a context menu. I know about future integration of context menu; that was just an example.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

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

20 Jul 2011, 18:58

hmm i mean, what is if you need a JS before the event and another JS after the event was triggered?
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

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

20 Jul 2011, 20:34

Yes, I meant the same. In the example above myBeforeFunction() is an JS function called before the onlick event on a row (= rowSelect). myAfterFunction() is called after :-)

You probably think about onstart, onsuccess, etc. callbacks. But <p:jsCommand .../> (a good candidate for the extension project ;)) doesn't trigger ajax requests, they don't make sense here.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

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

20 Jul 2011, 20:43

for example:
wizard navigate - maybe it is required to call JS before the navigation started and after the navigation was finished?

Puh! Don't know if it easy to build such an component in a extension project? Isn't it required to change primefaces JS?
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 45 guests