I have a session bean:
<managed-bean>
<managed-bean-name>mainMenuNavigationBean</managed-bean-name>
<managed-bean-class>com.cloud.common.jsf.core.beans.MainMenuNavigationBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
I inject this into a request bean:
<managed-bean>
<managed-bean-name>createAccountBean</managed-bean-name>
<managed-bean-class>com.cloud.common.jsf.account.CreateAccountBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>mainMenuNavigationBean</property-name>
<property-class>com.cloud.common.jsf.core.beans.MainMenuNavigationBean</property-class>
<value>#{mainMenuNavigationBean}</value>
</managed-property>
</managed-bean>
Now, I’m trying to use a setter in @PostConstruct of my createAccountBean but I do not understand why mainMenuNavigationBean is null here… I expect it to be autocreated if null, when accessing createAccountBean
@PostConstruct
public void init() {
userLoginVo = new UserLoginVo();
//NPE here
mainMenuNavigationBean.setExternalPage(true);
}
Can you give me a hint please? I can’t understand what I am doing wrong…
In order to get
<managed-property>to work properly, you need to ensure that the to-be-injected bean is apublicclass with a (implicit)publicdefault constructor which doesn’t throw any exception upon construction.And you need to ensure that the acceptor has a valid property and a working setter for that.
Mind the
thisin the setter, if you omit that, the setter has no effect.