user oncomplete callback called before extension oncomplete

UI Components for JSF
Post Reply
spauny
Posts: 75
Joined: 10 Oct 2011, 16:42

18 Sep 2017, 11:41

Hey guys, consider this piece of code from core.ajax.js:

Code: Select all

complete: function(xhr, status) {
        // this is your callback
        if(cfg.oncomplete) {
             cfg.oncomplete.call(this, xhr, status, xhr.pfArgs);
        }

        // this is the extension callback (datatable)
        if(cfg.ext && cfg.ext.oncomplete) {
             cfg.ext.oncomplete.call(this, xhr, status, xhr.pfArgs);
        }
https://github.com/primefaces/primeface ... re.ajax.js (line 572)

Why is the user oncomplete callback called before ext.oncomplete? I feel like I'm missing something here but since the DOM update and any other component updates usually happen in ext.oncomplete, this prevents users working with the updated components. For example, if you're using a page event in a datatable, oncomplete is called before the paginator.currentPage is actually updated.

I think this is counter intuitive since most users will expect oncomplete to be called after the DOM is updated.
The documentation is also a bit generic with regards to this:

Code: Select all

complete: (called) When everything finishes.

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

18 Sep 2017, 13:08

Good point - but not sure ifs valid for every case.

I think we have 2 perspectives here:
1) components enhance the already defined ajax event
Like for paging. The user probably defines the p:ajax with some options/listeners and the component enhances/specalizes this

2) a user can specialize the ajax call
lets e.g. take a case, where a user generates a ajax request manually via AjaxRequestBuilder
the can later on the client decide and additional register a oncomplete

for 1) it would be better to call ext before, for 2) it would be better to call after
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

spauny
Posts: 75
Joined: 10 Oct 2011, 16:42

18 Sep 2017, 14:36

Yes but you also have to take into account the likelihood of each scenario happening. How many users generate ajax requests manually? And if you're doing that you might as well define your own callbacks altogether.

I think it's really worth considering changing this and maybe adding a separate callback for scenario 2, something like: beforeComplete

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

18 Sep 2017, 17:22

Please create a issue ;)
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

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

21 Sep 2017, 12:45

Good sensible discussion and good investigation. Thanks! I second creating an issue.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 30 guests