I am trying to bind a dynamic hashmap to a form. It will put question name in the form and i want to get answer that user inputs. I can see my fields in form but don't see any question name and its value in hashmap in command object in my controller onSubmit method. Appreciate any help. My code is as follows.
<code>
Question.java
----------------
private String name;
private String label;
getter and setter methods
Command class:
------------------
private Map<String, Object> values= new HashMap<String, Object>();
public Map<String, Object> getValues() {
return values;
}
public void setValues(final Map<String, Object> map) {
this.values=map;
}
Controller class:
-------------------
protected Map<String, Object> referenceData(httpServletRequest request,
Object command, Errors errors)
throws Exception {
{
//here all question objects are added
Map<String, Object> data = super.referenceData(request, command, errors);
List<Question> questions = getAllQuestions();
if (questions != null && !questions.isEmpty()) {
data.put("myQuestions", questions);
}
return data;
}
jsp page:
----------
<c:forEach var="myQuestion" items="${myQuestions}">
<div id="customFieldSection" class="inputSection">
<div class="fieldName">
<label>
<c:set var="myQuestionLabel"><c:out value="${myQuestion.label}"/></c:set>
</label>
</div>
<div class="fieldValue">
<input id='${myQuestion.name}' path='values[${myQuestion.name}]'/>
</div>
</div>
</c:forEach>


Reply With Quote