Reputation: 686
I have a form that looks like this : cat1 [int field] cat2 [int field] cat3 [int field]
The fact is that my categories are different each time. How do i Handle this in my handler ?
Dont know how i should set my getter/setter
Heres my jsp :
<jsp:useBean id="formHandler" scope="page" class="com.pipo.EditStatusMappingHandler"><%--
--%><jsp:setProperty name="formHandler" property="*" /><%--
--%></jsp:useBean>
<form action="jsp/form/mapStatus.jsp" method="POST" name='categoryForm'>
<ul>
<foreach collection="<%= categorySet %>" type="Category" name="itCategory" >
<li>
<label for="<%= itCategory.getId() %>"><%= itCategory.getName(userLang) %></label>
<input type="text" name="<%= itCategory.getId() %>" id="<%= itCategory.getId() %>"/>
</li>
</foreach>
</ul>
<div class="modal-buttons buttons">
<input style="text-align:right;" class='formButton mainButton' type="submit"/>
</form>
I dont know what to put in my handler to get the input name = <%= itCategory.getId() %>
Upvotes: 0
Views: 253
Reputation: 533550
If you use a Map<String, Data>
the getters and setters are defined for you.
Map<String, Data> map = new LinkedHashMap<String, Data>();
// set values.
map.put("field1", data1);
map.put("field2", data2);
// get values.
Data dataA = map.get("field1");
Data dataB = map.get("field2");
Upvotes: 1
Reputation: 691795
Most of the Java web frameworks support mapped properties (i.e. getCategoryValue(String categoryName)
/ setCategoryValue(String categoryName, Integer value)
) or direct read-write access to a map inside the form bean/action bean.
Without knowing the framework you're using and what you mean by "handler", it's difficult to give a more precise answer."
Upvotes: 1
Reputation: 26428
Best way is to use reflection on the form object to get to know the category fields and invoke the corresponding operation.
Upvotes: 1