Question

I am using Stripes. My Action bean has a HashMap which has id(String) and quantity(int). On the JSP I am submitting a Form, the id and the quantity I want to map to the HashMap so that all the ids and quantity on the form are 'put' in the HashMap. How do I do it?

I have done something like -

In the ActionBean(with getter and setter) -

private Map<String, Integer> productVariantMap = new HashMap<String, Integer>();

on the JSP -

<s:useActionBean
beanclass="com.hk.web.action.core.b2b.B2BAddToCartAction" var="atc"/>
<s:useActionBean>

and I am picking up the values in the onsubmit through a loop and putting the values like

 ${atc:productVariantMap.put(id, quantity)};
 or 
 $(atc.productVariantMap.put(id,quantity)};

None of these works. Suggest me a way to map my HashMap or add these values as per my requirement. Thanks.

Was it helpful?

Solution

This is described in the documentation. Have a getter and a setter for your map in yhe action bean, and have input fields in the HTML form named like productVariantMap['foo'] (foo being a key of the map).

So for example, a form containing the following input fields will populate the map with 1 for the key "foo", and 2 for the key "bar":

<input type="text" name="productVariantMap['foo']" value="1"/>
<input type="text" name="productVariantMap['bar']" value="2"/>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top