Results 1 to 1 of 1
- 02-23-2012, 05:10 AM #1
Member
- Join Date
- Feb 2012
- Posts
- 1
- Rep Power
- 0
How to use Java Map between controller and DTO?
hi
i want to ask about java Map. Basically i'm trying to do a server side validation.
i have this portion inside my method here:
My CountryDTO:Java Code:@RequestMapping(value = "addCountry", method = RequestMethod.POST) public String addStep(@ModelAttribute("countryDTO") CountryDTO countryDTO, BindingResult result, Model model, HttpServletRequest request) { validator.validate(countryDTO, result); if (result.hasErrors()) { ResourceBundle rb = ResourceBundle.getBundle("messages"); Map<String, String> ERRORS = new HashMap<String, String>(); for (ObjectError errorobj : result.getAllErrors()) { String code = errorobj.getCode(); String fieldName = code.substring(code.indexOf('.') + 1, code.indexOf('[')); String message = rb.getString(code); model.addAttribute(fieldName + "error", message); } } }
And i have a CoreDTO that has these:Java Code:public class CountryDTO extends CoreDTO implements Serializable { private static final long serialVersionUID = 1L; @NotBlank(message="code is blank") @Length(max=4, message="code max length is 4") private String code; @NotBlank(message="description is blank") @Length(max=4, message="description max length is 4") private String description; public String getCode() { return code; } public void setCode(String code) { this.code = code; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } }
My form:Java Code:public class CoreDTO implements Serializable { private String errMsg; private Map<String, String> formErrors; public String getErrMsg() { return errMsg; } public void setErrMsg(String errMsg) { this.errMsg = errMsg; } public Map<String, String> getFormErrors() { return formErrors; } public void setFormErrors(Map<String, String> formErrors) { this.formErrors = formErrors; } }
My question is:Java Code:<tr> <td > Code: <input name="code" id="code" type="text" title="Country"><span><c:out value="${codeerror}" /></span></td> </tr> <tr> <td>Description: <input name="description" id="description" type="text" title="Description"><span><c:out value="${descriptionerror}" /></span></td> </tr>
1) how can i map the formErrors to the errorObjects? So, at the end how will i pass the error messages appropriately to my jsp using the mapped formErrors instead of simply passing it from message? I need all my errors collected to the CoreDTO, and countryDTO will getErrMsg from the CoreDTO.
additional info: the CoreDTO is extended to CountryDTOLast edited by soul_killer; 02-23-2012 at 05:14 AM.
Similar Threads
-
Need help for controller
By powerpravin in forum New To JavaReplies: 0Last Post: 04-12-2011, 06:07 AM -
Model View Controller with Java
By chopram in forum New To JavaReplies: 8Last Post: 06-07-2008, 09:18 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks