P. 1
JSF Lifecycle

JSF Lifecycle

|Views: 119|Likes:
Published by Hitesh Bhakuni

More info:

Published by: Hitesh Bhakuni on Aug 30, 2010
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as PPT, PDF, TXT or read online from Scribd
See more
See less





Prepared By : Rajat Gupta

process events 5. Invoke application. Update model values. process events 3. Apply request values. Process validations. process events 6.` The six phases of the JSF application lifecycle are as follows : 1. Render response . Restore view 2. process events 4.


The view is saved in a FacesContext object. In this case. initial view. . Initial view : (The first time a page is loaded).` This phase of the lifecycle presents three view instances: new view. JSF creates an empty view. so it needs only to be restored. The next phase after a postback is apply request values. JSF advances directly to the render response phase. Postback : (the user returns to a page she has previously accessed) the view corresponding to the page already exists. with each one being handled differently. From an initial view. New view : JSF builds the view of the Faces page and wires the event handlers and validators to the components. and postback. JSF uses the existing view's state information to reconstruct its state. The empty view will be populated as the user causes events to occur.

If any conversion fails then error message associated with the component is generated and queued on FacesContext. along with any validation errors resulting from the process validations phase. validation takes place in this phase instead of the Process Validations phase. If this property is set to true. The components must first be retrieved or created from the FacesContext object. Every input control that has an editable value also has an immediate property. followed by their values. . Component values are typically retrieved from the request parameters During this phase the default conversion takes place(like if any inputText is mapped to Integer in the bean).` The purpose of the apply request values phase is for each component to retrieve its current state. This message will be displayed during the render response phase.

Action sources. Once the action event has been created. also have an immediate property. During this phase. After this phase is completed. like a button or a hyperlink. it is added to the FacesContext for later processing in the Invoke Application phase. . any existing events are broadcast to interested listeners. the decoding code can also add events or perform other operations based on the request. and if that property is true. they will fire action events during this phase as well.

Once the component¶s submitted value has been validated. control will skip to the Render Response phase. JSF traverses the component tree and asks each component to make sure its submitted value is acceptable. the lifecycle continues onto the next phase. If both conversion and validation are successful for all components whose values were submitted. the submitted value is converted. complete with validation and conversion error messages.In the Process Validations phase. Before validation can occur. Otherwise. by using the converter registered for the component. its local value is set based on the converted submitted value .

If the local value has changed. At this point. value-change events (and any other events associated with this phase) are fired and consumed by the appropriate listeners. . These listeners have the option of outputting a response directly or jumping directly to the Render Response phase. the component also generates a value-change event.

searching each of the servlet scopes²request. As always.` The fourth phase of the JSF application lifecycle -. Because objects are associated with components through JSF EL expressions.numControls}". Only bean properties that are bound to a component's value will be updated. it¶s okay to deal with any associated backing beans or model objects. or application Once this phase has completed. session. and properties are updated based on the component¶s local value. JSF will use this to find an instance of a bean stored under the key helloBean. and of the correct type.updates the actual values of the server-side model -namely. . Now that we are sure all of the local values of the components are updated and valid.update model values -. this is where those expressions are evaluated. a listener could jump to the Render Response phase or return a response itself. by updating the properties of your backing beans (also known as managed beans). You can see that the value property is the expression "#{helloBean. the framework will broadcast any events to all interested listeners.

the JSF controller invokes the application to handle Form submissions. For example: on successful outcome. The component values will have been converted. Once the navigation occurs. For this navigation to work. you will have to create a mapping to the successful outcome as a navigation rule in the faces-config. and applied to the model objects. At this phase. You do this by defining a specific outcome for a successful form submission and returning that outcome. you also get to specify the next logical view for a given sequence or number of possible sequences. validated. .xml file.` ` At the fifth phase of the lifecycle -. move the user to the next page. you move to the final phase of the lifecycle. so you can now use them to execute the application's business logic.invoke application -.

you display the view with all of its components in their current state.` ` ` In the sixth phase of the lifecycle -.render response -. During the encoding process for each component. The secondary goal of this phase is to save the state of the view so that it can be restored in the Restore View phase if the user requests it again. converters are also invoked to translate the component values into strings for display .

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->