Where can I find an explanation/documentation of how each JSF component interacts with the page-lifecycle

StackOverflow https://stackoverflow.com/questions/15623933

質問

Often when using a UI component of JSF or one of it's 3rd party component libraries, I have a hard time finding the documentation that explains where in the lifecycle the attributes of these tags will kick in.

Let's say I want to use

<h:selectOneMenu valueChangeListener="#{myBean.myMethod1}" ... />

or

<h:commandButton action="#{myBean.myMethod2}" actionListener="#{myBean.myMethod3}" ... />

Where do I find information on where in the JSF lifecycle the valueChangeListener, the action or the actionListener is called, respectively?

Please understand that these are only examples. I'm trying to avoid coming to StackOverflow for each attribute of each component when I don't understand when exactly its method will be called.

If such a documentation does not exist (??), what debugging techniques would you suggest using to figure this out on a case-by-case basis?

役に立ちましたか?

解決

As to standard JSF attributes, you can find information in among others the JSF specification. The documentation states the following in chapter 2.5.1.3 about validations:

The converted value is pushed into the component's setValue() method, and a ValueChangeEvent is fired if the value has changed.

(thus, it's fired by end of conversion/validation and setting of local value)

And the following in chapter 7.3 about application actions:

An application action is an application-provided method on some Java class that performs some application-specified processing when an ActionEvent occurs, during either the Apply Request Values or the Invoke Application phase of the request processing lifecycle (depending upon the immediate property of the ActionSource instance initiating the event).

The following related questions may also be helpful in better understanding it:

As to 3rd party component libraries, look in its tag documentation or users guide. But generally they don't use custom events, but just standard JSF events or abstractions of standard ajax / HTML DOM events (which thus requires basic knowledge of ajax/HTML to start with).

As to debugging, well, easiest would be to put a breakpoint in the method being called and look in the call stack and/or the hit order. Mojarra uses for each phase a pretty self-documenting class like ProcessValidationsPhase which should clearly show up in the call stack somewhere after FacesServlet#service(). You could also log/print FacesContext#getCurrentPhaseId() or even call Thread#dumpStack() and read the stack trace in log and manually browse the associated classes.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top