Hi using JSF 1 (not JSF 2).
<h:inputText id="myElem"
value="#{backingBean.myElem}"
required="true"/>
<h:message id="myElemMsg" styleClass="errorMsg" for="myElem"/>
<h:inputText id="myElem2"
value="#{backingBean.myElem2}"
required="true"/>
<h:message id="myElem2Msg" styleClass="errorMsg" for="myElem2"/>
My message properties is:
javax.faces.component.UIInput.REQUIRED=A value is required.
Now the I get A value is required whenever anything is missing, however i want a custom message for myElem2 to say something else.
I understand that you're using JSF 1.0/1.1. You've then basically 2 options:
Create a custom validator.
<h:inputText id="myElem2"
value="#{backingBean.myElem2}"
validator="customRequiredValidator" />
Wherein you just throw a ValidatorException
with therein the desired message.
if (isEmpty(value)) {
throw new ValidatorException(new FacesMessage("Your message here"));
}
Or, simply upgrade to JSF 1.2. It introduces the requiredMessage
attribute.
<h:inputText id="myElem2"
value="#{backingBean.myElem2}"
required="true" requiredMessage="Your message here" />