Reputation: 48807
Below are 4 related posts I could find on Stack Overflow:
In these posts, the posters didn't know why they had this error message. In my case, I do know why I have this error, and I would like to change the default "Validation Error: Value is not valid" message to let's say "This is my message". How could I achieve this?
PS1: I already tried the requiredMessage
, validatorMessage
and converterMessage
attributes, but none of them get called in this special case.
PS2: I'm using RichFaces 4.1.0, so the drop-down list I'm using is the rich:select
one.
Scenario:
employee1
.employer1
, and link it to the employee1
via a drop-down list.employee1
from the database.employee1
isn't available anymore.This behavior is the one I expected, but I just would like to change the default message to another one, more user-friendly.
Upvotes: 2
Views: 2005
Reputation: 20691
All stock JSF messages are in the javax.faces
package of your JSF Distribution. The one you're looking for is with the key javax.faces.component.UISelectone.INVALID
(or UISelectMany
). Modify this property to get the results you want
Upvotes: 2
Reputation: 1108632
Supply a custom converter and throw it as converter exception in getAsObject()
.
Basically,
@Override
public Object getAsObject(FacesContext context, UIComponent component, String submittedValue) {
if (submittedValue == null || submittedValue.isEmpty()) {
return null;
}
Employee employee = findEmployeeInDatabase(submittedValue);
if (employee == null) {
throw new ConverterException("Sorry, unknown employee.");
}
else {
return employee;
}
}
Note that this also enables you to use converterMessage
.
Upvotes: 2