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 idanddefault message.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.And change the value for
javax.faces.component.UIInput.REQUIRED.For example your message bundle
language.propertiescould contain:Mostly all
JSFimplementations comes with the following default message, which I’ve copied fromMojarra:It’s also possible to define a required message to an single item with the
requiredMessageattribute. Then your<h:inputText />should look like this: