开发者

Spring MVC - Selective Formatting

I have a custom tag that extends Spring's InputTag to display numbers in the format ",###.0". I've registered a custom PropertyEditor for the Double class to handle the formatting.

When a form is submitted and validation fails, all invalid values should be re-disp开发者_开发技巧layed as-is, without any formatting, so that the user can see the mistake he made. How do I inform the custom tag of the validation result so that it does not do any formatting?

I'm using Spring MVC 3.

Thanks.


Override the getPropertyEditor() method of AbstractDataBoundFormElementTag, and return null instead of PropertyEditor instance (so the ValueFormatter will not pass the object value to PropertyEditor for formatting purpose).

public class CustomInputTag extends InputTag {
@Override
protected PropertyEditor getPropertyEditor() throws JspException {
    if(getBindStatus().getErrors().hasErrors()) {
        return null;
    }
    return super.getPropertyEditor();
   }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜