how to make custom validator in jsf
843844Mar 3 2008 — edited Mar 4 2008hi
i am using jsf for web designing in my projects.now we are using java script for JSF validation .but i am interested to do validation using validator tag of JSF.i have tried ,but it is not working.what can i do for this problem.can u give some simple examples with clear explanations.
My validator class file is
package com.obs.ftw.util.validation;
public class isEmpty implements Validator{
public isEmpty(){}
public void validate(FacesContext context, UIComponent uiComponent,Object value) throws ValidatorException{
System.out.println("Inside the validate");
FacesContext context=new FacesContext();
String firstName=(String)value;
if(StringUtils.isEmpty(firstName)){
FacesMessage message=new FacesMessage();
message.setSeverity(FacesMessage.SEVERITY_ERROR);
message.setSummary("First Name is Empty");
message.setDetail("First Name is Empty");
context.addMessage("Application:T5",message);
}
}
}
faces-config is
<validator>
<validator-id>isEmpty</validator-id>
<validator-class>com.obs.ftw.util.validation.isEmpty</validator-class>
</validator>
jsf page is
<h:message for="T5"></h:message>
<h:inputText value=#{mybean.lcFirstname} id="T5" required="true">
<f:validator validatorId="isEmpty"/>
</h:inputText>
this function calls isEmpty constructor.but system.out.println("Hi") isn't called which is defined inside the validate()
fuction.
any problem in this isEmpty function?any one give me a solution with an example
advance thanks
with regards
oasisdeserts