• 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 and lazy initialization

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the following code:



This is an example. In a nutshell, the getter gets called on the first page load and the test object is null as expected. After the first call, subsequent trips are made to this page to perform various actions (i.e. a save after a user enters new information), but the test instance variable continues to be null. I dont want to blow away anything the user enters with an older image from the database. This is very strange. I would expect subsequent trips to to result in a refresh from the viewstate. Could someone please let me know what I am missing?
 
Saloon Keeper
Posts: 27763
196
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
Code isn't enough. You didn't say what scope this bean is in. Request-scope beans get destroyed and recreated on each request, which causes any member variables you set to be lost.
 
Anthony Sykes
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The bean is in the request-scope. How can I effectively use lazy-initialization here. It seens like I will always have null?
 
Anthony Sykes
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to use lazy initialization with BackingBean. I would like to have the following scenario occur, a user hits the page for the first time and the bean is loaded from the database. When the user posts information to the page, the bean should not be loaded from the database. The problem is that when I use RequestBeans, the beanY instance variable is always null at the point the getBeanY is called after the post occurs. Every time. This renders this technique mentioned below unusable. If I am saving the viewstate why would this always be null. I am thoroughly confused? Can someone please tell me what I am doing wrong?
 
Tim Holloway
Saloon Keeper
Posts: 27763
196
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
I might be missing something here, because I'm not quite able to visualize the beans, their contexts and their relationships withot printing the question out and looking at the big picture. But being lazy, first I need to ask a stupid question: You're not mistaking the meaning of "request" scope are you? Request scope beans are destroyed and recreated for EVERY page load.

I have to ask, since a superficial reading of your question sounds like you're expecting the first page load to construct data that will be visible on subsequent page loads, and for that you'd need session scope.
 
Anthony Sykes
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Tim Holloway:
I might be missing something here, because I'm not quite able to visualize the beans, their contexts and their relationships withot printing the question out and looking at the big picture. But being lazy, first I need to ask a stupid question: You're not mistaking the meaning of "request" scope are you? Request scope beans are destroyed and recreated for EVERY page load.

I have to ask, since a superficial reading of your question sounds like you're expecting the first page load to construct data that will be visible on subsequent page loads, and for that you'd need session scope.




Maybe I should start with a different series of questions. What makes session scope beans more attractive than request scope beans? Because I am trying to avoid using session scope due to their extended stay in memory. What if I have a site where I am expecting 100000+ users sessions at any given time? Will tomcat be able to efficiently handle a scenario like this? I am also using POJO objects, no EJB's. Will this be a factor as well? I have been told that beans can be written out of memory as ppulled back in as needed. Does Tomcat handle this? How often does this occur? I should probably have started listing my initial concerns. I am a newbie to JSF.

Current Specs: JSF 1.2, POJO, Beans attached to component values rather than binding.
 
Anthony Sykes
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Anthony Sykes:



Maybe I should start with a different series of questions. What makes session scope beans more attractive than request scope beans? Because I am trying to avoid using session scope due to their extended stay in memory. What if I have a site where I am expecting 100000+ users sessions at any given time? Will tomcat be able to efficiently handle a scenario like this? I am also using POJO objects, no EJB's. Will this be a factor as well? I have been told that beans can be written out of memory as ppulled back in as needed. Does Tomcat handle this? How often does this occur? I should probably have started listing my initial concerns. I am a newbie to JSF.

Current Specs: JSF 1.2, POJO, Beans attached to component values rather than binding.



Also when I mention "Bean" I mean like the original post above.
 
reply
    Bookmark Topic Watch Topic
  • New Topic