The first "nonpostback" request to viewBean, someValue property in sessionBean is null. Now, in a postback request, I am setting a user input to someValue. The problem is that someValue is always null in any "nonpostback" request. Here is my code:
@ManagedBean
@ViewScoped
public class ViewBean implements Serializable {
@ManagedProperty(value = "#{sessionBean}")
private SessionBean sessionBean;
private String inputText;
@PostConstruct
public void init() {
if (sessionBean.getSomeValue() != null) // ALWAYS NULL
doSomething(sessionBean.getSomeValue());
}
private void doSomething(String s) {}
public void action(final ActionEvent ae) {
sessionBean.setSomeValue(getInputText());
doSomething(getInputText());
}
GETTERS/SETTERS
}
@ManagedBean
@SessionScoped
public class SessionBean implements Serializable {
private String someValue;
GETTER/SETTER
}
I feel I am doing something wrong. I am using Mojarra 2.1.2 Any advice is appreciated. Thank you.
UPDATE: Using evaluateExpressionGet on both methods (init and action) works fine:
FacesContext context = FacesContext.getCurrentInstance();
SessionBean sessionBean = context.getApplication().evaluateExpressionGet(context,
"#{sessionBean}", SessionBean.class);