Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

"on page load" in JSF

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

Could someone advise me how to implement a JSF page so that some method in a certain backing bean is executed each time the page is displayed to user? Something like "on page load" action

Thanks,
Tim
 
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A Backing Bean in a request scope can be one of the options.
Place your code/ method call in the constructor of the request scoped backing bean
and it will be invoked every time your jsp page is requested
 
Tim Wise
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks. Yes, agree. I also had that idea, but this doesn't work for me because non of the GUI components are initialized when the constructor is executed. If I have a control binding - those variables are not yet initialized.

I also tried to use @PostConstruct - but this doesn't work either - controls are not yet initialized by the time the method is executed. Although, I've been using SessionScoped bean in this test.. I'll try the RequestScope bean + PostConstruct - maybe this makes sense.
 
Tim Wise
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, so here is a workaround I use currently:

JSF page looks like:

Then, my bean looks like:

But this is not convenient at all... It works but I myself don't like the idea - I need to use a <h : outputText /> just to invoke the method, plus the method itself is getBlaBlaBla() instead of only blaBlaBla(). Is there a way to execute an arbitrary backing bean method from within JSF page?
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had same requirements in my project and I have used the requestscoped bean and put the code in a method marked @PostConstruct.
PostConstruct method gets called after constructor and all other initialization codes by the framework.

 
Slideshow boring ... losing consciousness ... just gonna take a quick nap on this tiny ad ...
The trailboss has a kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic