2
我有一個在會話範圍中定義的表單bean和一個在請求範圍中定義的控制器bean。我正在使用JSF將會話作用域bean注入到請求作用域bean中。幫我理解JSF託管bean生命週期
<managed-bean>
<managed-bean-name>Controller</managed-bean-name>
<managed-bean-class>
com.mycomp.Controller
</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>form</property-name>
<value>#{Form}</value>
</managed-property>
</managed-bean>
<managed-bean>
<managed-bean-name>Form</managed-bean-name>
<managed-bean-class>com.mycomp.form</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
的問題是,當我保存的形式我的持久層返回與ID的新豆,創建日期和其他屬性進行設置。然後我使用返回的bean設置本地bean。我是否也應該在此時設置會話作用域bean?
class Controller {
private Form form;
// getters and setters here
...
public void save() {
Form f = dataservice.save(form);
this.form = f;
// This
//FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("Form", form);
// or this?
//FacesContext.getCurrentInstance().getApplication().createValueBinding(
// "#{Form}").setValue(
// FacesContext.getCurrentInstance(), form;
}
}
我需要說明用戶在單擊保存後仍保留在同一頁面上,我希望看到數據服務返回的值。表單上的「創建日期」和「上次修改日期」字段綁定到Controller.form.createDate等。 – Future429 2009-11-30 19:18:12