This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSF and the fly likes Best to populate components with values when page loads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Best to populate components with values when page loads" Watch "Best to populate components with values when page loads" New topic
Author

Best to populate components with values when page loads

Nitin Katdare
Greenhorn

Joined: Oct 18, 2011
Posts: 6
Hi,

I am new to JSF, please can any one explain how am i suppose to populate/set some properties of components(based on some criteria) on first visit of page.
I have tried to use the PhaseListener, but when page is first visited ApplyRequest values does not occur.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15950
    
  19

The first thing that JSF does when asked to display a new page (View) is that the view is compiled and the "value=" expressions in the input and output controls are evaluated. Normally, those EL expressions reference properties in one or more backing beans, especially in the case of input controls. The backing bean's properties are queried to get the displayed values.

So you need to initialize the property values in the backing bean. If you do that, the display will automatically be initialized without the need to code any arcane JSF stuff - it's all POJO.

There are 2 ways to attack the particular case of setting data when a page loads. One is to invoke a setup routine in the backing bean from some other part of the application, which is a natural thing to do if the beans relate in some sort of workflow sequence. The other is to make the bean self-contained and add logic that is only called when the bean is first constructed or when the View is first requested. The @PostConstruct annotation can handle the case when you only want to initialize the bean once. Making a bean re-initialize itself on an "initial view" is trickier, but you can search this forum and find many discussions about that.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Best to populate components with values when page loads
 
Similar Threads
poplulate values of FormBean/reset/edit?
Swing performance
dropdown from database
Performance issue while loading JSP
Display a list based on JSP input