What is the a4j event sequence?

2019-04-16 20:20发布

问题:

What is the event sequence of a a4j:commandLink or a4j:commandButton?

Is it right: onclick->actionListner->oncomplete->reRender?

Is reRender comes before oncomplete?

When action happens?

回答1:

The onclick JavaScript is called the first when the enduser clicks the generated HTML element. When the JavaScript code does not return false, then all associated ActionListener implementations in the JSF side will be invoked, in the order of their association with the component. If the listeners haven't thrown any exception, then the real action will be invoked. When the action returns a successful response, then the components specified in reRender will be updated in the client side. Finally the oncomplete JavaScript will be called.

It's pretty easy to track yourself if you have a debugger in both the client and server side and know how to use it. I strongly recommend Firebug for the client side and Eclipse for the server side. You can of course also always do poor man's debugging using alert()s or System.out.println()s.