Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

prepopulate and update data

 
sunitha Veda
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Thanks!
[ February 17, 2005: Message edited by: sunitha Veda ]
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sunitha,

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.

Merrill
 
sunitha Veda
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic