HJW
HJW

Reputation: 23443

Change the default message "Validation Error: Value is required" to just "Value is required"

Can I modify this default required="true" validation message to show only "Value is required"?

formId:inputId: Validation Error: Value is required.

Upvotes: 12

Views: 18278

Answers (2)

BalusC
BalusC

Reputation: 1108632

Either use the input component's requiredMessage attribute:

<x:inputXxx ... required="true" requiredMessage="Value is required" />

Or create a properties file in the classpath which contains the custom message template:

javax.faces.component.UIInput.REQUIRED = Value is required.

and is been registered as message bundle in faces-config.xml:

<application>
    <message-bundle>com.example.CustomMessages</message-bundle>
</application>

The above example assumes that the file name is CustomMessages.properties and is been placed in com.example package. You can name and place it wherever you want.

You can find an overview of all message keys in chapter 2.5.2.4 of the JSF specification, such as javax.faces.component.UIInput.REQUIRED_detail in case you're using them.

Upvotes: 26

HJW
HJW

Reputation: 23443

I think i got it here.

Added label:

<p:inputText id="hotelName" value="#{editHotelBackingBean.hotel.name}" required="true" label="#{labelResource.hotelName}">

Now it looks like this:

Hotel Name: Validation Error: Value is required.

Upvotes: 2

Related Questions