• 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

ManagedProperty returning null

 
Ranch Hand
Posts: 99
Tomcat Server Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,

I already change from SessionScoped to ViewScoped and still not working.

Here is my code:

ModelBean



ShowSurvey - Here is where i want to use the gets from ModelBean



How can i get the 24?

Thanks,
-M
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks like you've attempted to set a local instance property (id) before the ModelBean instance was injected into the ShowSurvey bean instance. You did that by doing the assignment in open code within the ShowSurveyBean. Open code gets collected by the java compiled and placed into an anonymous internal init method. Static init code goes into a similar anonymous method (_clinit). These methods are run at "new" time, before the container (JSF) has had an opportunity to inject any properties.

To resolve this, you can either add a "@PostConfig" method to ShowSurveyBean or simply defer the initialization until the first time you need the id property OR you can simply not use the local id property and pull the id directly from modelBean when you need it.

A PostConfig annotation on a public void method tells JSF that this method will be invoked AFTER JSF has injected all the managed properties, but BEFORE any actual application processing is done.
 
It sure was nice of your sister to lend us her car. Let's show our appreciation by sharing this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic