In one sentence: the @ManagedProperty
annotation does return null
instead of injecting the property.
The details: there are two classes:
@ManagedBean(name="authFilter")
@SessionScoped
public class AuthFilter implements Filter {
@ManagedProperty("#{loginBean}")
private LoginBean loginBean;
public void setLoginBean(LoginBean loginBean) {
this.loginBean = loginBean;
}
...
}
and
@ManagedBean(name="loginBean")
@SessionScoped
public class LoginBean {
...
}
Now, AFAIK the the @ManagedProperty
annotation and the setter should be enough for the property to be injected, or at least the other questions here and BalusC's blog suggest this, but it still always remains null
.
It is also interesting and probably is related to this issue, that I get warnings for these classes that they are already have been registered as a managed bean, even though they only have been registered via the faces-config.xml
or with the annotataions. (
Tried them booth, separately, no difference.) If none of them is present, then the WARNINGs disappear, but the @ManagedProperty
does not work ofc.
WARNING: JSF1074: Managed bean named 'confListBean' has already been registered. Replacing existing managed bean class type <projectname>.web.authFilter with <projectname>.web.authFilter.
So the questions would be:
@ManagedProperty
to be injected what I am not doing?@notations
and faces-config.xml
? Is there a trace for the process which collects the managed beans I could check?When defining the loginBean, make sure you set the eager flag to true.
@ManagedBean(name="loginBean", eager=true)
This will ensure that the loginBean is created, even if it is not referenced from a GUI element.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With