This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
Per the Spring in Action, Third Edition, I inserted a @Size(min=2, max=6, message="First Name must be between 2 and 20 characters") in front of a private field like this in my domain class:
@NotEmpty
@Size(min = 2, max = 20, message="First Name must be between 2 and 20 characters")
private String firstName;
----
Then, in the JSP, I inserted the form:errors tag, like this:
Mark Spritzler wrote:Don't you have to turn it on, by adding some bean in the xml to tell Spring that you are using @Valid and to search for them?
Mark
Right. I just figured this out.
I had to add
to the applicationContext.xml file and then add the required Jar files (like the hibernate validation library).
Thanks for your reply.
mike
Cool, thanks for posting the answer too. I knew something had to be declared, but not specifically what.
Mark
Mike London
Ranch Hand
Joined: Jul 12, 2002
Posts: 953
posted
0
Glad to help here.
Getting the validation working was one of those "little things" that should be quick to implement, but due to the lack of end-to-end examples I found ended up taking a couple days...
I remember when I was trying to get my first validation project working, it seemed like enabling this was a big mystery. In the end, all I had to do was enable <mvc:annotation-driven> + all the things you said you did. I haven't looked but I suspect that this tag actually enables the validator bean you mentioned.