Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

How to customize JSF validation error message

How can I customize the validation message that appears when validation fails?

Here is the code I have:

<h:form>
    <p><h:inputText
           id="userNo"
           title="Type a number from 0 to 10:">
       <f:validateLongRange
           minimum="3"
           maximum="6"/>
       </h:inputText>

       <h:commandButton id="submit" value="Submit"
           action="response"/>
    </p>
    <h:message showSummary="true" showDetail="false"
        id="errors1"
        for="userNo"/>
</h:form>

Currently the message looks like this:

j_idt10:userNo: Validation Error: Specified attribute is not between the expected values of 3 and 6. 

Which is not particularly user-friendly.

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

The simplest way would be to set the validatorMessage="my custom message" attribute in the <h:inputText> tag.

For a more advanced way read this article Customize validation error message in JSF 2.0

And here a complete Reference to all available message that you can override in JSF 2.0.x


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...