Announcement Announcement Module
Collapse
No announcement yet.
Error messages are not shown in the user form, but exist in the BindingResult Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Error messages are not shown in the user form, but exist in the BindingResult

    Need your assistance. I am using the Spring Roo generated controller SignUpController:
    Code:
    @RequestMapping("/signup/**")
    @Controller
    public class SignUpController {
    
    List<ObjectError> signUpErrors;
    
    @Autowired
    private SignUpValidator validator;
    
    @ModelAttribute("UserRegistrationForm")
    public UserRegistrationForm formBackingObject() {
        return new UserRegistrationForm();
    }
    
    @RequestMapping(params = "form", produces = "text/html")//, method = RequestMethod.GET)
    public String createForm(Model uiModel) {
        populateSignUpForm(uiModel, new UserRegistrationForm());
        //uiModel.addAttribute("signUpErrors", signUpErrors);
        return "signup/index";
    }
    
    @RequestMapping(method = RequestMethod.POST, produces = "text/html")
    public String create(@Valid UserRegistrationForm userRegistration,
            BindingResult bindingResult, Model uiModel, HttpServletRequest request) {
        validator.validate(userRegistration, bindingResult);
        if (bindingResult.hasErrors()) {
            populateSignUpForm(uiModel, userRegistration);
            //uiModel.addAttribute("signUpErrors", bindingResult.getAllErrors());
            return "signup/index";
        }
    ...
    for a custom form-backing object UserRegistrationForm:

    Code:
    public class UserRegistrationForm {
        @NotNull(message="Must be filled.")
        @Size(min=6, max = 45)
        private String login;
        @Email
        private String email;
        @NotNull
        @Size(min=6, max = 45)
    ...
    and try to validate it using custom validator. I can show error messages to users, directly passing BindingResults into the jspx, and using the code as follows:

    Code:
    <c:if test="${signUpErrors.size()>0}">
            <util:panel id="title" title="${title}">
                <h2>
                    <spring:message code="signup_index_error" />
                </h2>
                <p></p>
    
                <c:forEach var="err" items="${signUpErrors}">
                    <br />
                    <tr>
                        <td>${err.objectName} </td>
                        <td>${err.codes} </td>
                        <td>${err.arguments} </td>
                        <td>${err.defaultMessage} </td>
                    </tr>
                </c:forEach>
            </util:panel>
            <p></p>
        </c:if>
    But the standard Roo and Spring tags don't work:
    Code:
    <field:input field="login"
            id="fc_.._UserRegistrationForm_login" required="true"
            z="" />
        <sf:errors path="login" cssStyle="error"></sf:errors>
        <field:input field="email"
            id="fc_.._UserRegistrationForm_email" required="true"
            z="" />
            <sf:errors path="*" cssStyle="error"></sf:errors>
    ...
    How to make it work?
    Last edited by dvperv; Aug 27th, 2012, 02:55 PM.
Working...
X