This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Rust Web Development and have Bastian Gruber on-line!
See this thread for details.
Win a copy of Rust Web Development this week in the Other Languages 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Why the getter method of managed-bean was invoked twice?

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wrote a very simlpe JSF page like this:


And the managed bean class like this:



When I input a name and submitted this page, the console output is:


I have 2 questions:
1. Why the getUserName() method was invoked twice by system? I supposed 1 time is correct.
2. When the tag <f:setPropertyActionListener/> be executed? It was said it will be executed before simple actionListener. However, it seems that this tag was not executed until 'sayHello' actionListener finished.

Please help, thanks!
 
Saloon Keeper
Posts: 24825
172
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
You should never assume that property getters on a backing bean will be called only once. In particular, don't do any side (state-changing) logic in getters for that reason. The bean's properties will be retrieved at multiple times in the JSF lifecycle as needed to prepare for update, display, and validate.

As far as the second question goes, I haven't studied that.
 
Wei Geng
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:You should never assume that property getters on a backing bean will be called only once. In particular, don't do any side (state-changing) logic in getters for that reason. The bean's properties will be retrieved at multiple times in the JSF lifecycle as needed to prepare for update, display, and validate.

As far as the second question goes, I haven't studied that.




Thanks for your answer to the first question.

Regarding to the second one, I guess I've got it.

According to the book 'Core JSF Programming', the method that is binded to 'actionListener' attribute in component tag will always been invoked earlier than the progressAction method of <f:actionListener> ActionListener.

In my opinion, <f:setPropertyActionListener> is a kind of <f:actionListener>. Therefore, its progressAction method will not be invoked until 'actionListener' attribute method finished.

I have made a test and it proved my guess.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic