I have scenario where a list of input fields from the jsp form would map to a HashMap field within the backing object Resolution.
@Controller
@RequestMapping("/rms")
class ResolutionManagementController{
private static final String ISSUE_FORM_PATH="/view/resolutionForm";
private static final String SHOW_RESOLUTION_PATH="/view/showResolution";
@Autowired
IIssueManagementService issueService;
@Autowired
ResolutionManagementService resolutionService;
@RequestMapping(value="/resolution/form",method=RequestMethod.GET)
String resolutionForm(Model model){
List<Issue> issues = issueService.listIssue();
model.addAttribute("issues",issues);
model.addAttribute("resolution", new Resolution());
return ISSUE_FORM_PATH;
}
@RequestMapping(value="/resolution",method=RequestMethod.POST)
String resolve(Resolution resolution,Model model){
List<SupportExecutive> executives = resolutionService.addResolution(resolution);
model.addAttribute("executives",executives);
return SHOW_RESOLUTION_PATH;
}
}
Backing Form Object
class Resolution{
private String resolutionId;
private String categoryId;
private Map<Issue,SupportExecutive> allotments;
//getters and setters
}
resolutionForm.jsp
<form:form action="/rms/resolution" commandName="resolution">
<c:forEach var="issue" items="${issues}">
<tr>
<td>
${issue.issueTitle}
</td>
<td>
<!-- What should i do so that issueTitle is converted
to Issue Object and stored as map key in allotments Map in resolution
object and the value entered by the user is converted to SupportExecutive
object and stored as corresponding value object of the allotments map-->
<input type="text" name="${issue.issueTitle}>"
</td>
</tr>
</c:forEach>
</form:form>
I tried to take a look at property editors but i am unable to understand how would i obtain the key and value and store in the map using property editor. Or may be they are not suited here.
What is the most cleanest way of achieving this ? It would be good if a detail explanation involving steps can be provided.
Aucun commentaire:
Enregistrer un commentaire