论坛首页 Java企业应用论坛

自定义校验对象如何进行客户端验证

浏览 2361 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2007-05-10  
最近在研究tapestry,对其它的客户端验证产生疑惑,代码如下:
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,进行客户端校验呢?请.
   发表时间:2007-05-10  
客户端验证只支持Tapestry内置的验证,自定义的验证是要通过java调用的,那是服务器端验证。
0 请登录后投票
   发表时间:2007-05-10  
的确是这样
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics