This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSF and the fly likes ManagedProperty returning null Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "ManagedProperty returning null" Watch "ManagedProperty returning null" New topic
Author

ManagedProperty returning null

Mauro Trevigno
Ranch Hand

Joined: Aug 27, 2012
Posts: 40

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
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15952
    
  19

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: ManagedProperty returning null
 
Similar Threads
Glassfish v3. javax.ejb.CreateException: Could not create stateless EJB
fill selectOneMenu from database
Unable to consume message from jms queue more than once using jsf
Problem integrating hibernate & EJB 3
Data source name not found