HTML and CSS Reference
In-Depth Information
Instead of using the @FacesValidator annotation, you can declare the validator in the JSF faces-config.xml file
as follows:
<faces-config ...>
...
<validator>
<validator-id>com.jsfprohtml5.EmailValidator</validator-id>
<validator-class>com.jsfprohtml5.example.validators.EmailValidator</validator-class>
</validator>
...
</faces-config>
Now, let's see how to use the EmailValidator in the JSF application. Listing 3-13 shows an updated version of
TestBean managed bean (shown originally in Listing 3-8) which includes an email attribute of type ( String ).
Listing 3-13. Updated Version of TestBean Managed Bean
public class TestBean implements Serializable {
// ...
private String email;
// ...
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
// ...
}
Listing 3-14 shows the EmailValidator validator XHTML test page.
Listing 3-14. EmailValidator XHTML Test Page
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html>
<html xmlns=" http://www.w3.org/1999/xhtml "
xmlns:h=" http://java.sun.com/jsf/html "
xmlns:f=" http://java.sun.com/jsf/core " >
<h:head>
<title>Email Validator Test</title>
</h:head>
<h:body>
<h:form>
<h1>Validator Test</h1>
<h:outputText value="Enter Email: "/>
<h:inputText id="email"
value="#{testBean.email}" required="true">
<f:validator validatorId="com.jsfprohtml5.EmailValidator"/>
</h:inputText>
<br/>
Search WWH ::




Custom Search