Why CDI don't inject my backing bean (session scope) in this ActionListener? The loginBean instance is always null. I have the impression that CDI does not manage the listener instances : it's right?
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ActionEvent;
import javax.inject.Inject;
public class CancelListener implements javax.faces.event.ActionListener {
private LoginBean loginBean;
@Inject
public void setLoginBean(LoginBean loginBean) {
this.loginBean = loginBean;
}
@Override
public void processAction( ActionEvent event ) throws AbortProcessingException {
loginBean.setLogin( "" );
loginBean.setPassword( "" );
}
}
Here the definition of my LoginBean class.
import java.io.Serializable;
import javax.enterprise.context.SessionScoped;
import javax.faces.event.ActionEvent;
import javax.inject.Named;
@Named
@SessionScoped
public class LoginBean implements Serializable {
private static final long serialVersionUID = -5433850275008415405L;
private String login = "james@mi6.uk";
private String password = "007";
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
And my listener is connected to the button with this code :
<h:commandButton value="Cancel" immediate="true">
<f:actionListener type="mypackage.CancelListener" />
</h:commandButton>
I know that i can use a method directly on the backing bean (connected with actionListener tag attribute), but I would like to understand how to make my class compatible with CDI and how to force the injection in this case. Thanks in advance.