我搞了一个在Tapestry4下的图片校验组件,它只有一个输入参数就是接受验证码,
并且支持服务端校验机制即当输入的验证码与图片显示不一致就会在验证提示信息中
提示错误。
1.先把lintw_jwc.jar导到项目下的lib目录下。
2.在application中配置类库。
<library id="linlib" specification-path="classpath:/com/lintw/jwc/lin.library"/>
3.在html及page中引入该组件
例:
[html]:
...
<body jwcid="@Body">
<table width="100%" border="0" cellspacing="10">
<tr>
<td>
<span jwcid="errorList">
<li class="style1"><strong>错误提示:</strong><span jwcid="errorItem">错误信息</span></li>
</span>
<form jwcid="validForm" name="form1" method="post" action="">
<table width="100%" border="0">
<tr>
<td align="right">校验码</td>
<td><input type="text" name="textfield" jwcid="validCode"/> <span jwcid="imageValid"/></td>
</tr>
</table>
<p>
<input type="submit" name="Submit" value="提交"/>
</p>
</form>
</td>
</tr>
</table>
</body>
...
[page]:
....
<!--校验窗体-->
<bean name="delegate" class="org.apache.tapestry.valid.ValidationDelegate"/>
<property name="errorRender"/>
<component id="errorList" type="Foreach">
<binding name="source" value="beans.delegate.errorRenderers"/>
<binding name="value" value="errorRender"/>
</component>
<component id="errorItem" type="Delegator">
<binding name="delegate" value="errorRender"/>
</component>
<component id="validForm" type="Form">
<binding name="delegate" value="bean:delegate"/>
<binding name="listener" value="listener:validSubmit"/>
</component>
<!--TextField-->
<property name="validCode"/>
<component id="validCodeText" type="TextField">
<binding name="value" value="validCode"/>
<binding name="displayName" value="literal:校验码"/>
<binding name="validators" value="validators:required"/>
</component>
<component id="imageValid" type="linlib:ImageValid">
<binding name="validCode" value="validCode"/>
</component>
...
注:valiCodeText要保证比imageValid先解析。
不足之处望大家多提宝贵意见。
并且支持服务端校验机制即当输入的验证码与图片显示不一致就会在验证提示信息中
提示错误。
1.先把lintw_jwc.jar导到项目下的lib目录下。
2.在application中配置类库。
<library id="linlib" specification-path="classpath:/com/lintw/jwc/lin.library"/>
3.在html及page中引入该组件
例:
[html]:
...
<body jwcid="@Body">
<table width="100%" border="0" cellspacing="10">
<tr>
<td>
<span jwcid="errorList">
<li class="style1"><strong>错误提示:</strong><span jwcid="errorItem">错误信息</span></li>
</span>
<form jwcid="validForm" name="form1" method="post" action="">
<table width="100%" border="0">
<tr>
<td align="right">校验码</td>
<td><input type="text" name="textfield" jwcid="validCode"/> <span jwcid="imageValid"/></td>
</tr>
</table>
<p>
<input type="submit" name="Submit" value="提交"/>
</p>
</form>
</td>
</tr>
</table>
</body>
...
[page]:
....
<!--校验窗体-->
<bean name="delegate" class="org.apache.tapestry.valid.ValidationDelegate"/>
<property name="errorRender"/>
<component id="errorList" type="Foreach">
<binding name="source" value="beans.delegate.errorRenderers"/>
<binding name="value" value="errorRender"/>
</component>
<component id="errorItem" type="Delegator">
<binding name="delegate" value="errorRender"/>
</component>
<component id="validForm" type="Form">
<binding name="delegate" value="bean:delegate"/>
<binding name="listener" value="listener:validSubmit"/>
</component>
<!--TextField-->
<property name="validCode"/>
<component id="validCodeText" type="TextField">
<binding name="value" value="validCode"/>
<binding name="displayName" value="literal:校验码"/>
<binding name="validators" value="validators:required"/>
</component>
<component id="imageValid" type="linlib:ImageValid">
<binding name="validCode" value="validCode"/>
</component>
...
注:valiCodeText要保证比imageValid先解析。
不足之处望大家多提宝贵意见。