开发者

JSF strange message from <h:message for="someID">

I'm using inputText to get input from a user

<h:inputText id="firstName" value="#{beanManager.currentUser.firstName }" required="true"        style="font-size: 15px"></h:inputText>

and then I've added a message tag

<h:message for="firstName"></h:message>

but when the inputtext is blank and I press submit I get this error message:

> j_id_jsp_1382885624_1:ID: Validation Error: Value is required.

how can I display the error message only as this?

> Validation Error: Value is required.

here is the code:

    <f:view>
    <h:form>
        <h:panelGrid border="1" columns="3" style="width: 643px; ">
            <h:outputText value="First Name" style="font-size: 25px; font-weight: bold"></h:outputText>
            <h:outputText value="Last Name" style="font-size: 25px; font-weight: bold"></h:outputText>
            <h:outputText value="ID" style="font-size: 25px; font-weight: bold"></h:outputText>
            <h:inputText id="firstName" value="#{beanManager.currentUser.firstName }" required="true" requiredMessage="Enter a Valid First Name" style="font-size: 15px"></h:inputText>
            <h:inputText id="LastName" value="#{beanManager.currentUser.lastName }" required="true" requiredMessage="Enter a Valid Last Name" style="font-size: 15px"></h:inputText>
            <h:inputText id="ID" value="#{beanManager.currentUser.ID}" required="true" requiredMessage="Enter a Valid ID"  style="font-size: 15px">
                </h:inputText>
            <h:form><h:commandButton action="#{beanManager.save }" value="Save Changes" style="height: 30px;开发者_运维百科 width: 100px"></h:commandButton>       
            </h:form>
        </h:panelGrid>
        <h:commandLink action="backtopersonalview" value="Back To Users" style="height: 30px; width: 100px">
                </h:commandLink>
    </h:form>
</f:view>


Yes, it's possible.

To the current message, I can say that it consists out of form id, item id and default message.

<form_id>:<item_id>: <default_message:javax.faces.component.UIInput.REQUIRED>

If you want to change the default message, you could do this with a message bundle, which you have to define in your faces-config.xml.

<application>
    <locale-config>
        <default-locale>en</default-locale>
        <supported-locale>en</supported-locale>
    </locale-config>
    <resource-bundle>
        <base-name>com.stackoverflow.messages.language</base-name>
    </resource-bundle>
</application>

And change the value for javax.faces.component.UIInput.REQUIRED.

For example your message bundle language.properties could contain:

javax.faces.component.UIInput.REQUIRED=Your new required message!

Mostly all JSF implementations comes with the following default message, which I've copied from Mojarra:

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

It's also possible to define a required message to an single item with the requiredMessage attribute. Then your <h:inputText /> should look like this:

<h:inputText id="firstName" value="#{beanManager.currentUser.firstName }" required="true" requiredMessage="Your new required message!" style="font-size: 15px">
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜