• Post Reply Bookmark Topic Watch Topic
  • New Topic

Explain this to me...  RSS feed

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So more on the whole filling a dropdown from the database issue. My backing bean is in request scope. I placed the code to load the select one menu with elements in the constructor. I also placed a log message in the constructor to see if it is being called everytime the page is request. I just have the single dropdown with a button that doesn't do anything but print out my selection choice on the console. So it posts back to the same page.

Now, my debug message prints on the console from the constructor everytime I load the page. So I didn't really want to call the database everytime because that just seemed silly to me. But I figured no matter where I moved that code, it was going to get called everytime because the page is in request scope. I went ahead though and moved the code to load the values into the getSelectOneMenu method which is just the getter for my component binding.

I also placed a debug message in there to see what happens. Low and behold that method is only called the first time the page is requested. But not again unless I navigate away from that page complety.

So my question is, why is the constructor being called everytime but the getter method isn't?
 
Varun Khanna
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Definition of Restore view phase


Restore View Phase
When a request for a JavaServer Faces page is made, such as when a link or a button is clicked, the JavaServer Faces implementation begins the restore view phase.

During this phase, the JavaServer Faces implementation builds the view of the page, wires event handlers and validators to components in the view, and saves the view in the FacesContext instance. The FacesContext instance contains all the information needed to process a single request. All the application's component tags, event handlers, converters, and validators have access to the FacesContext instance.
If the request for the page is an initial request, the JavaServer Faces implementation creates an empty view during this phase and the life cycle advances to the render response phase. The empty view will be populated when the page is processed during a postback.

If the request for the page is a postback, a view corresponding to this page already exists. During this phase, the JavaServer Faces implementation restores the view by using the state information saved on the client or the server.

From thefollowing link
[ July 08, 2005: Message edited by: Varun Khanna ]
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Varun. As always, a big help. It didn't click while I was reading as to why the constructor was always called until I read:

If the request for the page is a postback, a view corresponding to this page already exists. During this phase, the JavaServer Faces implementation restores the view by using the state information saved on the client or the server.
 
francisco roman
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gregg,
the thing is that loading the records in the constructor can
overwhelm the system. Would it be more appropriate to refresh
the records on demand and to display the records already cached?

Cheers.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!