package com.jspdev.ch17;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.*;

//Form，包含一个user属性。

public class UserForm extends ActionForm
{
	private User user=new User();
	public void setUserName(String userName)
	{
		user.setUserName(userName);
	}
	public String getUserName()
	{
		return user.getUserName();
	}
	public void setUser(User user)
	{
		this.user=user;
	}
	public User getUser()
	{
		return this.user;
	}
	//重新设置form
	public void reset(ActionMapping mapping, HttpServletRequest request)
    {
                    this.user = new User();
    }
    //form有效性判断，这里做简化处理。
     public ActionErrors validate(ActionMapping mapping,
                    HttpServletRequest request)
     {
        ActionErrors errors = new ActionErrors();
        if ((user.getUserName() == null) || (user.getPassword().length() < 3))
        { 
            errors.add("password", new ActionError("error.user.password"));
        }
        return errors;
     }
}
                
    