the commons-validator integration in Shale to work with facelets.
tonyshao Nov 23, 2010 9:28 PMDear everyone,
I've been trying to get the commons-validator integration in Shale to work with facelets.
Problem is
com.sun.facelets.tag.TagException: /index.xhtml @46,53 <s:validatorScript> Parent not an instance
of EditableValueHolder: javax.faces.component.html.HtmlForm@1543bc5
I'm a newbie to Shale and JSF in general. Since I'm using
com.sun.facelets.FaceletViewHandler as view handler,
That didn't work.
Then, I thought that maybe it needed a taglib, so I wrote one like this:
shale-validator.taglib.xml:
<?xml version="1.0"?>
<!DOCTYPE facelet-taglib PUBLIC
"-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
"http://java.sun.com/dtd/facelet-taglib_1_0.dtd">
<facelet-taglib xmlns="http://java.sun.com/JSF/Facelet">
<namespace>http://shale.apache.org/validator</namespace>
<tag>
<tag-name>commonsValidator</tag-name>
<validator>
<validator-id>org.apache.shale.CommonsValidator</validator-id>
</validator>
</tag>
<tag>
<tag-name>validatorScript</tag-name>
<validator>
<validator-id>org.apache.shale.ValidatorScript</validator-id>
</validator>
</tag>
</facelet-taglib>
index.xhtml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:s="http://shale.apache.org/validator">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>login</title>
</head>
<f:view>
<f:loadBundle basename="common.config.languages.messages" var="messages" />
<a4j:form id="loginForm" onsubmit="return validateForm(this);">
<div class="div_login">
<ul>
<li>
<label><h:outputText value="#{messages['login.adminName']}"/>:
<h:inputText id="adminName" styleClass="input" value="" >
<s:commonsValidator type="required" arg="#{messages['login.adminName']}" server="false" client="true" />
</h:inputText>
</label>
</li>
<li>
<label><h:outputText value="#{messages['login.password']}"/>:
<h:inputSecret id="password" styleClass="input" value="" >
<s:commonsValidator type="required" arg="#{messages['login.password']}" server="false" client="true" />
</h:inputSecret>
</label>
</li>
<li>
<label><h:outputText value="#{messages['login.verifyCode']}"/>:
<h:inputText id="verifyCode" styleClass="verifyCode" value="" >
<s:commonsValidator type="required" arg="#{messages['login.verifyCode']}" server="false" client="true" />
</h:inputText>
</label>
</li>
<li>
<label>
<h:commandButton styleClass="btn_login" value="submit" onclick="return validateForm(this.form);" ></h:commandButton>
</label>
</li>
</ul>
</div>
<h:message for="adminName"></h:message>
<s:validatorScript functionName="validateForm" />
</a4j:form>
</f:view>
</html>
Please give your suggestion.