Validation Error

Hi everyone

I have some issues with my validation messages since I use 9.7 instead of 7.1.3.

If I set on my text input field required = true. The validation message shows the id of the text input field. Is it possible to remove this id in the validation message?

My other problem is with a custom validator. In 9.7 the mws set to the validation message the css class “portlet-msg-info” instead of “portlet-msg-alert”. So the message is grey and not red like the is required message.

I hope someone can help me with this topic.

Kind regards
Andrin
standardvalidation.png

The default “required” message uses this pattern: “{0}: Validation Error: Value is required.” Where {0} is replaced by the label associated with that input control. If no label attribute is specified, then it uses the clientId as the label.

Alternatively, JSF 2.x supports supplying your own custom message via the “requiredMessage” property of the input control that is used instead of the default message.

For your custom validator, can you provide a snippet of how you are raising the ValidatorException? The FacesMessage you pass to the ValidatorException constructor has the ability to specify the Severity (see [1]).

  1. [url]FacesMessage (JavaServer Faces API (2.0))

Thank you for your fast reply.

Do you know if it’s possible to change the pattern of the default message?

This is my snippet from the custom validator.

throw new ValidatorException(new FacesMessage(msg));

msg is a String with a localized message.

Supplying your own custom message via the “requiredMessage” property of the control is the best practice way of changing the message as it would ensure that both the client-side validation and server-side validation use your custom text.

I haven’t tested this, but you may try raising the ValidatorException with a different severity (the default is FacesMessage.SEVERITY_INFO) with something like this to affect how it is displayed:

throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, null));

Of course that would be a solution but than I have to change every text input that is required. I will try to avoid this because I have tons of portlets :roll:

So maybe someone has an idea to change the default is required message. I found that post [url]https://mobiarch.wordpress.com/2013/07/18/user-friendly-validation-error-message-in-jsf-2/[/url] but for my portlet that solution doesn’t work.

The problem with the custom validation is solved. Thank you for your help.

Well, sometimes you’ll have to actually do some work.

I found a solution for my problem.

Add

javax.faces.component.UIInput.REQUIRED =Validation Error: Value is required.

to the AppResources.properties to customize the “is required” message.

So I have to adjust every portlet but this is easier than to modify every single text input field.