Reputation: 16117
I want to update a table in my database, but before that I will show the user his current information. now I have this form bean.
I have a form bean in my action class called.
public void setProfileBean(UserProfile profileBean) {
this.profileBean = profileBean;
}
public UserProfile getProfile() {
return profileBean;
}
And I want its value to be populated first from another bean inside the session scope. How would I achieve that using the model driven interface?
Upvotes: 1
Views: 3370
Reputation: 2390
well first of all ,why you need in use of model-driven interface, in your case you can simply render the bean on your view using action-support.,you have to something like this:
1: first you should populate the view before you want to update, i mean ,at the time you are redirected to your page from which you are going to update your database,on that time you should populate the data on view.
2: You can achieve this by making some changes in your action:
in your action
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;
}
Thats it, doing this struts2 will automatically populate the data on your view, make sure you have defined properties like this:
<s:property value="UserProfile .xyz">
Upvotes: 1
Reputation: 368
As @roman suggested Struts2 ModelDriven interface works fine to solve such situations for some code help regarding how to use it you can refer to This link
Upvotes: 1