• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What could cause this?

 
A Harry
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My app submits a form that contains a text field called "firstfield".

In my action class I can retrieve it's value from the request object -

String firstTransfer = request.getParameter("firstfield");

This action is then forwarded to another action BUT this field (in fact every parameter read or not read) is now null!

Any ideas why this might happen?

The form is "multipart/form-data", could this be the reason? even though during this request no file is uploaded?

thanks

harry
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you're doing is called "action chaining" and it's not recommended. If you want to pass parameters on to another action, you have to re-send the parameters in the query string. Example:

String url = "myAction.do?firstfield="+request.getParameter("firstfield");
return new ActionMapping(url, false);

A better alternative would be to use an ActionForm bean and have Struts automatically populate the properties of the bean rather than reading the parameters. The ActionForm does get passed on to a second action without jumping through hoops.
 
A Harry
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Merrill, adding it to the Form sorted it!

can I ask why chaining actions is not recommended? in fact if the action is forwarded what happens to the request parameters?
[ December 08, 2006: Message edited by: A Harry ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic