1 package org.springframework.samples.jpetstore.web.struts; 2 3 import java.util.ArrayList ; 4 import java.util.List ; 5 6 import javax.servlet.http.HttpServletRequest ; 7 8 import org.apache.struts.action.ActionError; 9 import org.apache.struts.action.ActionErrors; 10 import org.apache.struts.action.ActionForm; 11 import org.apache.struts.action.ActionMapping; 12 13 public class BaseActionForm extends ActionForm { 14 15 16 17 public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { 18 ActionErrors actionErrors = null; 19 ArrayList errorList = new ArrayList (); 20 doValidate(mapping, request, errorList); 21 request.setAttribute("errors", errorList); 22 if (!errorList.isEmpty()) { 23 actionErrors = new ActionErrors(); 24 actionErrors.add(ActionErrors.GLOBAL_ERROR, new ActionError("global.error")); 25 } 26 return actionErrors; 27 } 28 29 public void doValidate(ActionMapping mapping, HttpServletRequest request, List errors) { 30 } 31 32 33 34 protected void addErrorIfStringEmpty(List errors, String message, String value) { 35 if (value == null || value.trim().length() < 1) { 36 errors.add(message); 37 } 38 } 39 40 } 41 | Popular Tags |