我想更新数据库中的表,但在此之前我会向用户显示他当前的信息。现在我有这个表单bean。
我的动作类中有一个名为。
的表单beanpublic void setProfileBean(UserProfile profileBean) {
this.profileBean = profileBean;
}
public UserProfile getProfile() {
return profileBean;
}
我希望它的值首先从会话范围内的另一个bean填充。如何使用模型驱动的界面实现这一目标?
答案 0 :(得分:1)
正如@roman建议的Struts2 ModelDriven接口可以很好地解决这种情况,有关如何使用它的一些代码帮助,你可以参考This链接
答案 1 :(得分:1)
首先,为什么你需要使用模型驱动的接口,在你的情况下你可以使用action-support简单地在你的视图上渲染bean。你必须这样:
1:首先,您应该在想要更新之前填充视图,我的意思是,当您被重定向到要从中更新数据库的页面时,您应该在视图上填充数据。
2:您可以通过对行动进行一些更改来实现此目的:
行动中
public void setProfileBean(UserProfile profileBean) {
this.profileBean = profileBean;
}
public UserProfile getProfile() {
return profileBean;
}
**i assume this is your target method**
public string execute()
{
UserProfile user=new UserProfile();
user.setProfileBean("whatever you want to set");
......
......
return SUCCESS;
}
就是这样,执行此struts2会自动填充视图中的数据,确保您已定义如下属性:
<s:property value="UserProfile .xyz">