File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes prepopulate and update data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "prepopulate and update data" Watch "prepopulate and update data" New topic

prepopulate and update data

sunitha Veda

Joined: Feb 17, 2005
Posts: 3
Hello ,

I am able to prepopulate the form by forwarding teh form to an intermediate action class. But after prepopulation, if I try to save the data as it is, without updating, all teh values in the form bean are null (unless I manually set the values). How is it able to populate then.

Please help me in understanding it.
[ February 17, 2005: Message edited by: sunitha Veda ]
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864

I'd love to help, but I'm afraid I can't make sense of what you are doing. It would be helpful if you could be more specific on what the flow of information is, and at what point the values are null. It would also be helpful to indicate what the scope each of the forms are in. For example:

1. user calls actionA
2. actionA populates FormA
3. ActionA puts FormA in the request
4. JspA reads values in FormA and values are null.

One of the biggest mistakes made by beginners in struts is that they forget to place the form bean in the proper scope object. For example, if the form is scoped to the session, in the Action class, you must include the statement:

request.getSession().setAttribute("MyForm", myForm);

if the form is scoped to the request, you must include the statement:

request.setAttribute("MyForm", myForm);

This assumes that the name of your form is MyForm, and that you have defined a variable of type MyForm named myForm, and have poplulated it's values.

If this explanation solves your problem, great.

If not, please provide the information I asked for, and I'll try to help you figure this out.


Consultant, Sima Solutions
sunitha Veda

Joined: Feb 17, 2005
Posts: 3
Hi Merrill,
I am really glasd that you are trying to help me out.

This is the flow of the application -

1. To update the employee info, I enter his name in a text field and click update.
2. In the LookupDispatchAction, update() method, I request get his info in database.

3. Then, in the same update method, I create
MyForm myForm = new MyForm();
Implement all the setters say, myForm.setAge() myForm.setDate() etc... with the values from the database.

4. Still in teh update method, I say,
request.setAttribute("myForm", myForm);
return mapping.findforward("update");

5. In the update screen, I see that teh form is populated with the relevant information.

6. At this point of time, if I decide not to update and click save, all teh form valeus are null.

Thanks for yoru time!
I agree. Here's the link:
subject: prepopulate and update data
It's not a secret anymore!