随笔 - 37  文章 - 29  trackbacks - 0


常用链接

留言簿(3)

随笔分类

随笔档案

最新评论

阅读排行榜

评论排行榜

用Struts Validate机制,因为一个form需要在多个页面进行操作,不同页面会有不同的验证需求,所以我采用了ValidatorActionForm

代码如下:
public class UserForm extends ValidatorActionForm {
    private Integer id;
    private String name;
    private String password;
    private String confirmpwd;
    private String email;
    private Integer sex;
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    ...
}
Action类略过
validation.xml:
<formset>
        <form name="/register/register">
            <field property="name" depends="required">
                <arg0 key="user.name"/> 
            </field>
            <field property="confirmpwd" depends="required">
                <arg0 key="user.confirmpwd"/>
            </field>
        </form>
    ...

ApplicationContext.properties:
user.name = {0}\u6d93\u5d88\u5158\u6d93\u8679\u2516
    ...

编译后,ApplicationContext.properties能在WEB-INF\classes下找到,且struts-config.xml里也已添加

JSP页面:
    ...
<html:form action="/register/register" method="post" enctype="multipart/form-data">            
    <input type="hidden" name="method" value="register" />   
    <div class="reg03">
        <html:text property="name" styleId="name" style="width:245px" />
        <font color="red"><html:errors property="name"/></font>        
    </div>
    ...

结果:验证起作用,但是提示信息打印不出来。 
HELP!!!

已解决
需要修改validation.xml和ApplicationContext.properties
validation.xml:
    ...
<field property="name" depends="required">
    <msg name="required" key="user.required"/>
    <arg0 key="user.name"/>
    ...

ApplicationContext.properties (未转码前)
    ...
user.name=姓名
user.required={0}不能为空
    ...




posted on 2008-06-15 00:58 EvanLiu 阅读(1621) 评论(0)  编辑  收藏 所属分类: Struts

只有注册用户登录后才能发表评论。


网站导航: