aspose file tools*
The moose likes JSF and the fly likes Regarding jsf request processing lifecycle Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Regarding jsf request processing lifecycle" Watch "Regarding jsf request processing lifecycle" New topic
Author

Regarding jsf request processing lifecycle

An Me
Greenhorn

Joined: Nov 28, 2013
Posts: 10
Suppose on my initial page itself I'm having the following markup
<h:form>
<h:selectOneMenu value="#{model.serviceLevel}">
<f:selectItems value="#{model.serviceLevelArray}"/>
</h:selectOneMenu>
<h:commandButton value="Show Details" actionListener="#{model.getDetails}"/>
</h:form>

Now,as the page is displayed, the f:selectItems will be populated with managed bean class Model's property serviceLevelArray elements and the drop-down menu is shown with a button 'Show Details'.
My doubt is:
This is an initial request for a page and the request goes through only Restore View and Render Response phases.Then in which phase the values are getting populated for the drop-down menu ??
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16250
    
  21

For an initial page request, Restore View is more about making sure the necessary Models are all present. They will be constructed if they don't already exist and populated with any managed properties. And for more recent JEE implementations, if there's a @PostConstruct on a Model object, that method will be execured.

The Render Response phase is where the Model property values are actually retrieved and used to populate the HTML that's being generated by Render Response.

The actual construction of the dropdown menu model properties (selectitem list and value) is done by your Model code. This can be done by the constructor, by @PostConstruct, or when a "get" method is invoked. I often construct my SelectItem lists on their first "get" and cache them for the benefit of subsequent "get" requests. That makes it easy to update the list, since all that's required to trigger a new list construction is to invalidate the old list.

On Postback handling, when an Action method is invoked, the Action can modify the Model data. Whatever changes the Action logic makes to the Model are reflected when the response is rendered.


Customer surveys are for companies who didn't pay proper attention to begin with.
An Me
Greenhorn

Joined: Nov 28, 2013
Posts: 10
In my code there is a Model class which has the following private String[] serviceLevelArray={"ABC","SDF","FGH"}.
So when the initial request for the page comes,it first goes through the Restore View phase which creates a view/component tree and instantiates all the related managed beans including this Model class(which is a managed bean) and hence the EL #{model.serviceLevelArray} for f:selectItems in .xhtml page gets the value.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16250
    
  21

The sub-Model for selectitems cannot be a simple String array. The SelectItem object itself is a label/value pair, so you are missing half of what is needed.

You CAN direct JSF2 to construct an anonymous SelectItem list from an object array or collection, BUT you have to inform it where to obtain the value and where to obtain the label. It's explained in the JavaDocs.

Note that there is a degenerate constructor "SelectItem(String)" that only takes one parameter. It's useful for when the displayed label and the selection value are identical, and it's simply a shorthand for "SelectItem(x, x)", where "x" is the string whose text you want to use as the label and the value.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Regarding jsf request processing lifecycle