浏览 2361 次
锁定老帖子 主题:自定义校验对象如何进行客户端验证
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2007-05-10
html: <html> <head> </head> <body jwcid="@Body"> <table width="400" border="1"> <form jwcid="loginForm"> <tr> <td colspan="2" width="100%" align="center"> <span jwcid="@Insert" value="ognl:errorMsg"/> </td> </tr> <tr> <td colspan="2" width="100%" align="center">LOGIN</td> </tr> <tr> <td width="32%" align="right">Username:</td> <td align="left"><input type="text" jwcid="username" size="20"/></td> </tr> <tr> <td width="32%" align="right">Password:</td> <td align="left"><input type="password" jwcid="password" size="20"/></td> </tr> <tr> <td align="center"><input type="submit" value="Login"/></td> <td> <input jwcid="startDate@DatePicker" value="ognl:startDate" displayName="Start Date"/></td> </tr> <tr> <td colspan="2" align="center"><a href="#" jwcid="registe">Registe</a></td> <td colspan="2" align="center"><a href="#" jwcid="showAjax">ShowAjax</a></td> </tr> </form> </table> </body> </html> page: <page-specification class="com.suzsoft.framework.example.web.pages.Home"> <property name="password"/> <property name="errorMsg"/> <property name="startDate"/> <bean name="passwordValidator" class="com.suzsoft.framework.common.PasswordValidator"></bean> <bean name="delegate" class="org.apache.tapestry.valid.ValidationDelegate"></bean> <component id="loginForm" type="Form"> <binding name="listener" value="listener:loginSubmit"/> <binding name="clientValidationEnabled" value="true" /> <binding name="delegate" value="beans.delegate"></binding> </component> <component id="username" type="TextField" > <binding name="value" value="username" /> <binding name="validators" value="validators:required"/> </component> <component id="password" type="TextField"> <binding name="value" value="password"></binding> <binding name="validators" value="beans.passwordValidator"/> <binding name="hidden" value="true"/> </component> <component id="registe" type="PageLink"> <binding name="page" value="literal:Registe"></binding> </component> <component id="showAjax" type="PageLink"> <binding name="page" value="literal:ShowAjax"></binding> </component> </page-specification> 自定义校验对象java文件: public class PasswordValidator implements Validator { public void validate(IFormComponent field, ValidationMessages message, Object object) throws ValidatorException { String password = (String) object; if (!"123456".equals(password)) { throw new ValidatorException("The password is invalid!"); } } public boolean getAcceptsNull() { return true; //To change body of implemented methods use File | Settings | File Templates. } public boolean isRequired() { return true; //To change body of implemented methods use File | Settings | File Templates. } public void renderContribution(IMarkupWriter writer, IRequestCycle cycle, FormComponentContributorContext context, IFormComponent field) { writer.attribute("style","background-color:#999999"); } } 为何我clientValidationEnabled==true,只有username产生客户端验证,而password却没有在客户端产生javascript,进行客户端校验呢?请. 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2007-05-10
客户端验证只支持Tapestry内置的验证,自定义的验证是要通过java调用的,那是服务器端验证。
|
|
返回顶楼 | |
发表时间:2007-05-10
的确是这样
|
|
返回顶楼 | |