user590586
user590586

Reputation: 3050

Custom error message from entity class

How can I create a custom message for the errors that accour in the field annotation?

@Size(max = 10)

or

@Column(name = "NAME"  , length = 10) 

Now I see a message

CustomerDetailsForm:customerName: Validation Error: Length is greater than allowable maximum of ''10'' .

How can I change this message?

Upvotes: 1

Views: 775

Answers (1)

BalusC
BalusC

Reputation: 1108557

Use the message attribute of the bean validation annotation.

@Size(max=10, message="May not be more than 10 characters.")

To internationalize it, supply ValidationMessages.properties bundle files in the desired locales and use the {} to specify the bundle key, e.g:

@Size(max=10, message="{validation.max_size}")

Alternatively, you can also just use maxlength on the <h:inputText> field so that the enduser already won't be able to enter too much characters.

<h:inputText ... maxlength="10" />

Upvotes: 2

Related Questions