aspose file tools*
The moose likes Struts and the fly likes How to add parameters to the action dynamically Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to add parameters to the action dynamically" Watch "How to add parameters to the action dynamically" New topic
Author

How to add parameters to the action dynamically

Simpson Kumar
Ranch Hand

Joined: Mar 19, 2008
Posts: 261
I have a shopping cart application, for this can show the list of the products with the following way

Product Image | SKU | Price | QTY (textbox) | Add to Cart (hyperlink)


Here, when we click on the Add To Cart link, I'm calling an action and adding the item to the cart (session), here I can get the ProductNumber and price as parameters (because they are from collection object. but how can I get the quantity parameter (it is dynamic values added by user). I'm not getting how to grab that value into my action class.


Thanks,
Kumar
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You're basically implementing a form without an actual form? (Why *aren't* you using a form--it'd make your requirement substantially easier.) Also, if you're not in a form, using the <html:text...> tag is probably a Bad Idea, as it expects an ActionForm to be in scope.

If you're dead-set on doing things this way I'd probably recommend implementing a link "onclick" handler that takes the link as it is, adds the quantity, and return true so the link will be followed.
Simpson Kumar
Ranch Hand

Joined: Mar 19, 2008
Posts: 261
Hi David,

I got the same idea to use onClick event and call the action in the javascript function, but I'm not getting the idea to add the quantity field in the onClick's javascript function.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to add parameters to the action dynamically