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

JSF action and action listener method execution time.

 
Ranch Hand
Posts: 160
IntelliJ IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 160
IntelliJ IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Good night. Drive safely. Here's a tiny ad for the road:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic