• 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 ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Best to populate components with values when page loads

Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
Saloon Keeper
Posts: 27919
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 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.
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic