Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

jsf - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...