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 JSF action and action listener method execution time. 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 "JSF action and action listener method execution time." Watch "JSF action and action listener method execution time." New topic
Author

JSF action and action listener method execution time.

Riaan Nel
Ranch Hand

Joined: Apr 23, 2009
Posts: 157

Hi Everybody

I've recently started working on a project, using JSF. I'll admit that my knowledge of JSF is very limited, and I've run into a problem.

On one of my pages, I've got a button that updates a session variable from an action method in a request scoped backing bean when it's clicked. The constructor of the backing bean makes use of this variable to set up some of the stuff displayed on the page. The problem is that the constructor of the page appears to be called before the action method, thereby leaving my page in an incorrect state. The following SSCCE should demonstrate the problem.

faces-config.xml


TestBean.java


test.jsp


When clicking the button on the above page, the following is printed to the console:
In constructor
In actionListenerMethod()
In actionMethod()

Could anyone please gice me some pointers on solving my problem? Your opinions will be much appreciated. Thanks a lot!

Regards,
Riaan


"The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man." - George Bernard Shaw
Kavita Tipnis
Ranch Hand

Joined: Sep 21, 2008
Posts: 177
Constructor will always run first.
I guess your problem is , you have a request scoped bean, which is constructed(a new instance is created) everytime you hit test.jsp.
To keep session information, you either have to make your bean session scoped or add your variables to the session map in the actionlistener
Riaan Nel
Ranch Hand

Joined: Apr 23, 2009
Posts: 157

Kavita Tipnis wrote:Constructor will always run first.
I guess your problem is , you have a request scoped bean, which is constructed(a new instance is created) everytime you hit test.jsp.
To keep session information, you either have to make your bean session scoped or add your variables to the session map in the actionlistener

Hi Kavita.

Thank you for your reply. I've considered using a session scoped bean, but that introduces a host of new issues, i.e. when the user navigates back to the particular page that I mentioned above and sees his/her old data when they're expecting a blank page.

For future reference; I've added a navigation case for my action method to the faces-config xml, and forced a redirect using <redirect />. That seems to have fixed a number of issues, including the one that I discussed above.

Cheers
 
Don't get me started about those stupid light bulbs.
 
subject: JSF action and action listener method execution time.
 
Similar Threads
commandLink param problem
General problems with some beginner stuff
Navigation problem
message /.jsp not found in JSF2.0+RichFaces3.3.3+Tomcat6.0.29
problem on JSF application