How to know the execution order of the JSF component methods

Asked

Viewed 2,169 times

2

How do I find out which order to execute methods in ? My doubt is based on the following, once a button was firing late a method, as it had not chosen correctly the method of the button.

In this link the guy responds to the execution sequence.

  • The question is not very clear. The answer is what is on the link?

  • 1

    This has much more to do with Javascript / http requests and AJAX callbacks than with the JSF lifecycle. The API of each component (e. g., commandLink) indicates which tag attribute corresponds to each event type. Think of it as if there was no JSF in the middle (onclick is processed in the client before the request, then the ajax request happens - action - you update the DOM - update - and can do more - oncomplete).

  • Right, but is there any way, website, manual or anything like that?

  • @bfavaretto yes, the answer of the link is my doubt, but the question of the link is not mine, it is more a curiosity. Because sometimes in a project using JSF with Primefaces, I come across a situation like, a button will be blocked or not if the datatable this filled....

  • @Anthonyaccioly I saw the javadoc, interesting, the information it contains describing on which side occurs the methods. But more information where I find? For example you said that the action updates the DOM...

  • 1

    In fact the update does (see utluiz response). To my knowledge there is no integrated manual detailing this (perhaps some book or course of Primefaces). I think this is because the documentation assumes a certain familiarity with JSF AJAX and Javascript (in theory the sequence should be intuitive). But take a look at User Guide. Especially in tags AjaxBehavior, AutoComplete and CommandButton, as well as in Chapter 4 - Partial Rendering and Processing and 6 - Javascript API. All the components end up being similar.

Show 1 more comment

1 answer

3


If I understand correctly, you want to better understand the sequence of events between the presentation layer (Javascript) and the controllers (Managed Beans).

This post Prime Faces' blog explains how the callback Ajax oncomplete, onsuccess and onstart.

The general order would be as follows:

  • onstart: request start event that executes a javascript.
  • actionListener: updates properties on manabed bean.
  • action: performs specified action of manabed bean.
  • onsuccess / onerror: events javascript executed if there was a success or error in the action, respectively.
  • update: updates DOM components to reflect actions performed via javascript, but can call methods used by updated components via postback.
  • oncomplete: javascript event executed after everything was completed, error or not

About action and actionListener

A action is the action where the business rules will effectively execute, usually culminating in a navigation. The method of action usually returns a string.

The actionListener is like an event that occurs before the action in order to update values, perform some validation, log, etc. You can also cancel the action if necessary. In a actionLisener, you can access the values sent by the user through the parameter ActionEvent before that JSF updates the properties of ManagedBean.

I’ve seen some developers mistakenly access properties from ManagedBean at the event actionListener and record them in the database. Only then do they realize that the values are outdated.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.