webwork提供了强大的验证功能,下边一一介绍一些常用的功能的用法。
一,首先webwork的validator是基于拦截器的,所以首先要配制一下拦截器,默认的拦截器,已经
使用了validator,假如你想定义自己的拦截器组合,记得在你的拦截器的stack中把这句话加入

四、客户端验证
加入validate="true"
<ww:form name="test" action="javascriptValidation" validate="true">
...
</ww:form>
这样的话webwork会根据你的服务器端的验证,对应生成Javascript的验证,而且提示信息和服务器端
验证的方式一样,而不是alert的方式显示。(前题是你使用的都是标准的验证器)
五、
对应上边验证器的web页面

<%@page contentType="text/Html; charset=UTF-8" pageEncoding="UTF-8"%>

<%@ taglib PRefix="ww" uri="/webwork"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>

<head>

<title></title>

<ww:head />

</head>

<body>

<!--

假如想统一的显示所有的Erro打开下边这句

<ww:fielderror />

假如想显示其中一个Error打开下边这句,默认显示在字段的正上方

<ww:fielderror>

<ww:param value="%{'name'}" />

</ww:fielderror>

<ww:fielderror>

<ww:param>desc</ww:param>

</ww:fielderror>

-->

<ww:form name="test" namespace="/" action="DbAdmin" method="post" validate="true">

<ww:actionmessage />

<ww:actionerror/>

<ww:textfield label="name" name="name" />

<ww:date id="strCurrDate" name="currDate" format="yyyy-MM-dd" />

<ww:datepicker name="currDate" id="currDate" showstime="true"

format="%Y-%m-%e %H:%M" CSSClass="tx" language="zh" required="true"

template="datepicker.ftl" label="currDate" value="%{strCurrDate}" >

</ww:datepicker>

<ww:textfield label="url" name="url" />

<ww:textfield label="mail" name="mail" />

<ww:textfield label="age" name="age" />

<ww:textfield label="desc" name="desc" />

<ww:submit action="DbAdmin" method="doTestValidator"

value="doTestValidator" />

</ww:form>

</body>

</html>

六、对应上边的Action代码

package niis.web.actions.temp;


import java.text.SimpleDateFormat;

import java.util.Date;


import niis.persistence.ITestDao;

import niis.persistence.dao.SqlCommand;

import niis.web.actions.AbstractAction;



public class DbAdminAction

{

private String name;

private Date currDate ;

private String url;

private String mail;

private int age;

private String desc;


public String doTestValidator()

{

System.out.println(name);

System.out.println(currDate);

System.out.println(url);

System.out.println(mail);

System.out.println(age);

return SUCCESS;

}


/** *//**

* @return the age

*/


public int getAge()

{

return age;

}


/** *//**

* @param age the age to set

*/


public void setAge(int age)

{

this.age = age;

}


/** *//**

* @return the date

*/


public Date getCurrDate()

{

return currDate;

}


/** *//**

* @param date the date to set

*/


public void setCurrDate(Date date)

{

this.currDate = date;

}


/** *//**

* @return the mail

*/


public String getMail()

{

return mail;

}


/** *//**

* @param mail the mail to set

*/


public void setMail(String mail)

{

this.mail = mail;

}


/** *//**

* @return the name

*/


public String getName()

{

return name;

}


/** *//**

* @param name the name to set

*/


public void setName(String name)

{

this.name = name;

}


/** *//**

* @return the url

*/


public String getUrl()

{

return url;

}


/** *//**

* @param url the url to set

*/


public void setUrl(String url)

{

this.url = url;

}


/** *//**

* @return the testDao

*/


public ITestDao getTestDao()

{

return testDao;

}


/** *//**

* @return the desc

*/


public String getDesc()

{

return desc;

}


/** *//**

* @param desc the desc to set

*/


public void setDesc(String desc)

{

this.desc = desc;

}

}