1

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?

Roman C
  • 49,761
  • 33
  • 66
  • 176
user962206
  • 15,637
  • 61
  • 177
  • 270

2 Answers2

1

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

Community
  • 1
  • 1
CodeHunter
  • 378
  • 1
  • 3
  • 16
1

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">
arvin_codeHunk
  • 2,328
  • 8
  • 32
  • 47