Hey guys, hoping to get a hand here before my head pops =)
I'm creating a webshop where a product is supposed to be based on a template and recieve several attribute containers. An attribute has a name and optionally a measurement, while the actual value of the attribute is stored in a HashMap<Attribute,
String> in the Product bean. This is to dynamically and easily create different types of products that always have a given set of attributes.
For instance, a product named Cat would have the Animal template, which has the "Number of paws" and "Favorite food" attributes. The values of the attributes would in this case be <Number of paws, "4"> and <Favorite food, "Whiskas">. My problem arises when I try to create a product like this using a
jsp.
My flow is like this:
a) User selects a template.
b) Get the ArrayList of attributes in the chosen Template and create a textfield in my jsp for each using a
Struts 2 iterator. The textfields are currently created this way:
<s:textfield name="attributeValues['+#{iteratorStatus.index}+']"/>
c) Create a new hashmap<attribute, string> in the action class to populate.
d) User fills out all fields required to create a Product, as well as values to each attribute in the chosen template.
e) Validate input. Attribute values are not validated.
f) A new Product instance is created using the specified input and saved to the DB. This is done during Execute, using a builder
pattern bean.
The problem is, my hashmap doesn't live past the initialisation of the action class, so at the time of validate (the attributes are not used in Validate) and execute my new hashmap is null.
So, where should I define my hashmap and how do I get it to survive long enough to be set into the newly created Product at the time of Execution?