How to implement jsf validator?
- by Krishna
HI,
I want to know how to implement Validator in JSF. What is the advantages of declaring the validator-id. When it will be called in the life cycle?. I have implemented the following code. Please find out what is wrong in the code. I am not seeing it called anywhere in the life cycle.
<?xml version="1.0"?>
<!DOCTYPE faces-config PUBLIC
"-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
"http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
<faces-config>
<lifecycle>
<phase-listener>javabeat.net.jsf.JsfPhaseListener</phase-listener>
</lifecycle>
<validator>
<validator-id>JsfValidator</validator-id>
<validator-class>javabeat.net.jsf.JsfValidator</validator-class>
</validator>
<managed-bean>
<managed-bean-name>jsfBean</managed-bean-name>
<managed-bean-class>javabeat.net.beans.ManagedBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<navigation-rule>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>success.jsp</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>
public class JsfValidator implements Validator {
public JsfValidator()
{
System.out.println("Inside JsfValidator Constructor");
}
@Override
public void validate(FacesContext facesContext,
UIComponent uiComponent,
Object object)
throws ValidatorException {
System.out.println("Inside Validator");
}
}