本帖最后由 lucky_xingxing 于 2011-12-14 11:29 编辑
李振元 发表于 2011-12-13 22:44
肯定有问题,楼主不妨把代码贴出来。。。
Formbean:
public class RegUserForm extends ValidatorForm {
/*
* Generated fields
*/
/**
*
*/
private static final long serialVersionUID = 1L;
/** name property */
private String name;
/** password property */
private String password;
private String password2;
private String birthday;
private String email;
/*
* Generated Methods
*/
/**
* Returns the name.
* @return String
*/
public String getName() {
return name;
}
/**
* Set the name.
* @param name The name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* Returns the password.
* @return String
*/
public String getPassword() {
return password;
}
/**
* Set the password.
* @param password The password to set
*/
public void setPassword(String password) {
this.password = password;
}
public String getBirthday() {
return birthday;
}
public void setBirthday(String birthday) {
this.birthday = birthday;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPassword2() {
return password2;
}
public void setPassword2(String password2) {
this.password2 = password2;
}
}
validation.xml配置文件
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE form-validation PUBLIC
"-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.1.3//EN"
"http://jakarta.apache.org/commons/dtds/validator_1_1_3.dtd">
<form-validation>
<!-- ========== Default Language Form Definitions ===================== -->
<formset>
<form name="regUserForm">
<field property="name"
depends="required">
<arg key="prompt.username"/>
</field>
<field property="password"
depends="required, minlength,maxlength">
<arg key="prompt.password"/>
<arg key="${var:minlength}" name="minlength"
resource="false"/>
<arg key="${var:maxlength}" name="maxlength"
resource="false"/>
<var>
<var-name>maxlength</var-name>
<var-value>6</var-value>
</var>
<var>
<var-name>minlength</var-name>
<var-value>3</var-value>
</var>
</field>
<field property="password2"
depends="required,validwhen">
<arg key="prompt.password2"/>
<msg name="validwhen" key="errors.password2"/>
<var>
<var-name>test</var-name>
<var-value>(*this* == password)</var-value>
</var>
</field>
<field property="email"
depends="required">
<arg key="prompt.email"/>
</field>
<field property="email"
depends="email">
<arg key="prompt.email"/>
</field>
<field property="birthday"
depends="required">
<arg key="prompt.birthday"/>
</field>
<field property="birthday"
depends="date">
<arg key="prompt.date"/>
<var>
<var-name>datePatternStrict</var-name>
<var-value>yyyy-MM-dd</var-value>
</var>
</field>
</form>
</formset>
</form-validation>
struts-config.xml配置文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">
<struts-config>
<data-sources />
<form-beans >
<form-bean name="regUserForm" type="com.lovo.validator.form.RegUserForm" />
</form-beans>
<action-mappings >
<action
attribute="regUserForm"
input="/WEB-INF/page/regUser.jsp"
name="regUserForm"
parameter="xxx"
path="/regUser"
scope="request"
type="com.lovo.validator.action.RegUserAction">
<forward name="false" path="/regUserUI.do" />
<forward name="succes" path="/WEB-INF/page/main.jsp" />
</action>
<action path="/regUserUI" type="com.lovo.validator.action.RegUserUIAction">
<forward name="regUI" path="/WEB-INF/page/regUser.jsp" />
</action>
</action-mappings>
<message-resources parameter="com.lovo.resources.ApplicationResources" />
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property
property="pathnames"
value="/WEB-INF/validator-rules.xml,
/WEB-INF/validation.xml"/>
</plug-in>
</struts-config>
jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<html>
<head>
<title>JSP for RegUserForm form</title>
</head>
<body>
<html:form action="/regUser">
name : <html:text property="name"/><html:errors property="name" prefix="" suffix="" header="" footer="" /><br/>
password : <html:password property="password"/><html:errors property="password" prefix="" suffix="" header="" footer=""/><br/>
password2 : <html:password property="password2"/><html:errors property="password2" prefix="" suffix="" header="" footer=""/><br/>
email:<html:text property="email"/><html:errors property="email" prefix="" suffix="" header="" footer="" /><br/>
birthday : <html:text property="birthday"/><html:errors property="birthday" prefix="" suffix="" header="" footer="" /><br/>
<html:submit/><html:cancel/>
</html:form>
</body>
</html>
|