wood burning stoves 2.0*
The moose likes JSF and the fly likes 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 ""on page load" in JSF" Watch ""on page load" in JSF" New topic
Author

"on page load" in JSF

Tim Wise
Greenhorn

Joined: Jul 25, 2009
Posts: 15
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
Kavita Tipnis
Ranch Hand

Joined: Sep 21, 2008
Posts: 177
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

Joined: Jul 25, 2009
Posts: 15
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

Joined: Jul 25, 2009
Posts: 15
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?
Smitha H Rao
Ranch Hand

Joined: Oct 20, 2007
Posts: 50
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.


Free Mock tests Interview questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: "on page load" in JSF
 
Similar Threads
method invocation
Can we Access FacesContext outside FacesServlet
JSTL if statement does not work
first button click reloads page
preloading message