reset password
Author Message
xytian
Posts: 70
Posted 23:21 May 09, 2013 |

I have same validation codes for user registration as in the springmvc example. The validation seems to work (if all fields supplied, there is new entry in the database, otherwise it returns to the registration page).
However, there is no error message displaying. I noticed that the already-entered-fields also disappear. Any known cause?   (There is a warning in jsp "List is a raw type. References to generic type List<E> should be parameterized" for "<form:errors", but it is not likely to be the problem).

 

cysun
Posts: 2935
Posted 08:35 May 10, 2013 |

There's no way to tell exactly what went wrong based on what you described. Just read the sample code carefully and see if you missed anything.

xytian
Posts: 70
Posted 02:37 May 11, 2013 |

It turns out that every time an error occurs, the registration form fields are populated with a new User object instead of using the binding  results.

In "GET" method:
        models.put("newuser", new User());
        return "registerUser";
In "POST" method:
    public String registeruser(@ModelAttribute User newuser,
            BindingResult bindingResult)
    {
        userValidator.validate(newuser, bindingResult);
        if( bindingResult.hasErrors()) {
            System.out.println("I am an error");                   //This line displays.
            return "registerUser";
        }
        .......
    }

xytian
Posts: 70
Posted 15:18 May 11, 2013 |

I solved it! Odd enough, just change the name of ModelAttributes then it works fine: newuser -> user, newlawyer->lawyer. It doesn't like the word "new"