JSF Custom Validation Help

Hi

I am trying to display error message when a input text field is blank.

But i am getting inbuilt message there. Please help.

<td align="left"><font color="red">*</font> Service Name:</td>

<td align="left"><input type="text" jsfc="h:inputText" value="#newServiceBackingBean.serviceName}" id="serviceName" title="serviceName" size="25" maxlength="50" required="true" requiredMessage="#{messages.SERVICENAME_LABEL}" /></td>

<!--<td align="left"><input type="text" jsfc="h:inputText" value="#{newServiceBackingBean.serviceName}" id="serviceName" title="serviceName" size="25" maxlength="50" required="true" /><br/><font color="red"><h:message for="serviceName"/></font></td>-->

<td align="left"><h:message for="serviceName" showDetail="true"/></td>

</tr>

This is my properties file...

it has

SERVICENAME_LABEL=no service name specified .

Thanks

Sri

[1043 byte] By [sriia] at [2007-11-27 2:03:25]
# 1

Shale has some great code for these common needs. If you can't use Shale in your app, you can at least leverage some of its code:

This snippet comes from the AbstractViewController bean that many Shale users extend when writing their managed beans. Add it to your base bean (or each individual bean, if you like being repetitive). Note the getFacesContext method included below.

This method assumes that you have the UIComponent bound to the managed bean and that there is an h:message tag associated with the tag on the page. Summary can be any String message you like.

/**

*

Enqueue a <code>FacesMessage</code> (associated with the

* specified component) containing the specified summary text and a

* message severity level of <code>FacesMessage.SEVERITY_ERROR</code>.

*

* @param component Component with which this message is associated

* @param summary Summary text for this message

*/

protected void error(UIComponent component, String summary) {

FacesContext context = getFacesContext();

context.addMessage(component.getClientId(context),

new FacesMessage(FacesMessage.SEVERITY_ERROR, summary, null));

}

/**

*

Return the <code>FacesContext</code> instance for the

* current request.

*/

protected FacesContext getFacesContext() {

return FacesContext.getCurrentInstance();

}

James_Ra at 2007-7-12 1:45:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Thanks a lot...it worked.
sriia at 2007-7-12 1:45:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...