對於viewBean的第一個「nonpostback」請求,sessionBean中的someValue屬性爲null。 現在,在回發請求中,我將用戶輸入設置爲someValue。問題是someValue在任何「nonpostback」請求中始終爲空。 這裏是我的代碼:會話Bean正在丟失?
@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
}
我覺得我做錯了什麼。我正在使用Mojarra 2.1.2 任何建議表示讚賞。謝謝。
UPDATE: 在這兩種方法(init和動作)使用evaluateExpressionGet正常工作:
FacesContext context = FacesContext.getCurrentInstance();
SessionBean sessionBean = context.getApplication().evaluateExpressionGet(context,
"#{sessionBean}", SessionBean.class);
如果我們想保持'javax.faces.STATE_SAVING_METHOD'到'client'任何解決方案? – blo0p3r