Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Best to populate components with values when page loads

 
Nitin Katdare
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18020
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic