package jp.yoyoyoyo.webformmanager.form;

import javax.servlet.http.HttpServletRequest;


import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

public class UserManagerForm extends ActionForm {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private String operatorId;
	
	private String search;
	
	private String newUser;
	
	private String next;
	
	private String prev;

	public String getOperatorId() {
		return operatorId;
	}

	public void setOperatorId(String operatorId) {
		this.operatorId = operatorId;
	}

	public String getSearch() {
		return search;
	}

	public void setSearch(String search) {
		this.search = search;
	}

	public String getNewUser() {
		return newUser;
	}

	public void setNewUser(String newUser) {
		this.newUser = newUser;
	}
	
	

	public String getNext() {
		return next;
	}

	public void setNext(String next) {
		this.next = next;
	}

	public String getPrev() {
		return prev;
	}

	public void setPrev(String prev) {
		this.prev = prev;
	}
	
	public String getSearchString(){
		String where = " where 1 = 1";
		
		if(!(operatorId == null)){
			if(!operatorId.equals("")){
				where += " and ";
				where += "OPERATOR_ID Like '%" + operatorId + "%'";
			}			
		}
		
		return where;
	}
	
	public ActionErrors checkValidate(ActionMapping mapping,
			HttpServletRequest req){

		ActionErrors errors = new ActionErrors();
		
		String operatorId = req.getParameter("operatorId");
		
		if(operatorId != null && !operatorId.equals("")){
			if(operatorId.length() > 20){
				errors.add("operatorId", new ActionMessage("error.userManager.operatorId.length"));
			}
		}
		
		return errors;
	}
}
