cancel
Showing results for 
Search instead for 
Did you mean: 

Inject spring bean into managed backing bean (jsf)

lee
Champ in-the-making
Champ in-the-making
I want to use one of my spring bean classes in a jsf backing bean.

For example I have a spring bean called: configuration.
So I've put this in the jsf bean:

<managed-property>
           <property-name>configuration</property-name>
            <value>#{configuration}</value>
        </managed-property>

But when the code tries to use the configuration class it throws a null pointer (because the configuration object isn't there.

Any idea how to get around this? I really don't want to have to duplicate all sorts of code in the jsf backing bean.

Thanks
Lee
2 REPLIES 2

jayjayecl
Confirmed Champ
Confirmed Champ
Do you have, in your Java class (represented by the JSF bean) written the "configuration property" and the dedicated the setter method :



public Configuration configuration;

public void setConfiguration(Configuration configuration) {
         this.configuration = configuration;
}

lee
Champ in-the-making
Champ in-the-making
Hi JayJay,

Thanks for your response. Yes I do have a dedicated setter method. However a null object always gets injected to the jsf bean.

I was, however, shown a workaround by Brian R from Ixxus:

You need to use a static member of the class

public class JSFObject {
   private static Configuration config;

   public void setConfig(Configuration config) {
     JSFObject.config = config;
   }

Then create both a spring bean that injects the required object (in this case: Configuration). Then all instances of the jsf bean will share the same configuration object.