开发者

Add error message for <f:validateLength> tag customised for a field

开发者 https://www.devze.com 2023-01-28 10:04 出处:网络
I have many fields on witch I have to validate length. It\'s not a problem with <f:validateL开发者_运维知识库ength> tag. I can also add custom message for this validator.

I have many fields on witch I have to validate length. It's not a problem with <f:validateL开发者_运维知识库ength> tag. I can also add custom message for this validator.

The problem is the message should be customised for each field. E.g. firstname field should have messages "First name too short" or "First name too long", surname should have "Surname too short" or "Surname too long" etc. How to achieve that in JSF2.0?


Use the label attribute.

<h:inputText label="First name">

The {1} in the message template will be substituted with this.

javax.faces.validator.LengthValidator.MAXIMUM: {1} too long.     
javax.faces.validator.LengthValidator.MINIMUM: {1} too short.
0

精彩评论

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