Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to add parameters to the action dynamically

 
Simpson Kumar
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 261
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic