amorfis
amorfis

Reputation: 15770

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

I have many fields on witch I have to validate length. It's not a problem with <f:validateLength> 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?

Upvotes: 4

Views: 5051

Answers (1)

BalusC
BalusC

Reputation: 1108537

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.

Upvotes: 5

Related Questions