Markos Fragkakis
Markos Fragkakis

Reputation: 7781

JSF Validation message

I am using JSF 1.2 and Richfaces 3.3.FINAL. I have an inputText which must be a number between 1 and 999999999999.

<h:inputText id="prodId" required="true" value="#{product.productId}" maxlength="12" >
    <f:validator validatorId="anotherValidatorValidator" />
    <f:validateLongRange minimum="1" maximum="999999999999"/>
</h:inputText>

I want my validation message to basically say that the user must enter a number between 1 and 99...9. In case I enter the number -1 and submit the form, this is the message that appears, which is what I want.

If however I write letters in the field, say 'abcd' i get :

prodId: 'abcd' must be a number between -9223372036854775808 to 9223372036854775807 Example: 98765432

This message is confusing for the users because, if the suggested negative numbers are submitted, the other validateLongRange validator will throw a message, now asking for numbers between the correct range.

The second message occurs because a ConverterException is thrown when the submittes String is cast to a Long (which is the type of the backing bean property) and the message javax.faces.component.UIInput.CONVERSION_MESSAGE_ID appears.

Can I somehow override it (not for all ConverterException cases, just the specific one), or make the message of the other validateLongRange appear?

Upvotes: 2

Views: 7833

Answers (1)

BalusC
BalusC

Reputation: 1109532

That message is actually coming from javax.faces.converter.LongConverter.LONG_detail and would only appear when you've configured h:message(s) with showSummary="false" and showDetail="true". The default (summary) message is would otherwise have been javax.faces.converter.LongConverter.LONG which is {2}: ''{0}'' must be a number consisting of one or more digits. which in turn makes more sense.

If changing the message detail display is also not what you're after and you really want to have the converter to display exactly the same message as the LongRangeValidator, then your best bet is to supply a custom converter which displays the desired message. You however have to hardcode the message yourself since JSF doesn't support any API facilities to grab the default message message template.

Upvotes: 3

Related Questions