HTML and CSS Reference
In-Depth Information
As you will notice, EmailValidator constraint has the same logic of the JSF EmailValidator class that we
developed in Listing 3-12. However, there is one main difference: in JSF validator, when the validation fails, the
validator throws an exception, but in the Java Bean Validation, the validator returns false. The initialize() method
is used for initializing the custom constraint; it is important to note that this method is guaranteed to be called before
any of the other constraint implementation methods.
Now, after building our custom constraint, we are ready to use the built-in and custom constraints in our JSF
XHTML page. Listing 3-18 shows the subscriber application main page ( index.xhtml ).
Listing 3-18. The Subscriber Application XHTML Page
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html>
<html xmlns=" http://www.w3.org/1999/xhtml "
xmlns:ui=" http://java.sun.com/jsf/facelets "
xmlns:h=" http://java.sun.com/jsf/html "
xmlns:f=" http://java.sun.com/jsf/core " >
<ui:composition template="/WEB-INF/templates/default.xhtml">
<ui:define name="title">
#{bundle['application.subscriber.title']}
</ui:define>
<ui:define name="content">
<h:form>
<h:panelGrid columns="3">
<h:outputText value="#{bundle['user.name']}"></h:outputText>
<h:inputText id="userName"
value="#{person.name}"
required="true"
requiredMessage="#{bundle['user.name.required']}">
</h:inputText>
<h:message for="userName" styleClass="errorMessage"/>
<h:outputText value="#{bundle['user.address']}"></h:outputText>
<h:inputText id="address"
value="#{person.address}"
required="true"
requiredMessage="#{bundle['user.address.required']}">
</h:inputText>
<h:message for="address" styleClass="errorMessage"/>
<h:outputText value="#{bundle['user.email']}"></h:outputText>
<h:inputText id="email"
value="#{person.email}"
required="true"
requiredMessage="#{bundle['user.email.required']}">
</h:inputText>
<h:message for="email" styleClass="errorMessage"/>
</h:panelGrid>
 
Search WWH ::




Custom Search