• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Regarding jsf request processing lifecycle

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ??
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
An Me
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Mo-om! You're embarassing me! Can you just read a tiny ad like a normal person?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic