Use error in form without a field binding?
I am wondering whether you can use a <form:errors> tag to display an error that doesn't have a binding to a field in the co开发者_StackOverflow中文版mmand object. Basically I want to do some custom validation logic that isn't directly related to a single form element, but perhaps many or all, or none. What if I only wanted to validate forms from 9am to 3pm?
I tried creating a global error like Errors.reject("myError"), but then how do I put this in the jsp? Must I make an attribute just for this in the command object?
With Spring Errors you have the choice to use it for:
- errors for an specific field in the command object, but this field must exist.
- global errors, that are not associated to any field.
To access global errors in the JSP, you could use <form:errors />
without path
attribute or you can access the error variable in a direct way: (@see http://static.springsource.org/spring/docs/1.2.x/taglib/tag/BindErrorsTag.html for a list of variables)
To enable the validation only between 9am to 3pm you need to implement you own validator.
精彩评论