KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > samples > jpetstore > web > struts > BaseActionForm


1 package org.springframework.samples.jpetstore.web.struts;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.List JavaDoc;
5
6 import javax.servlet.http.HttpServletRequest JavaDoc;
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   /* Public Methods */
16
17   public ActionErrors validate(ActionMapping mapping, HttpServletRequest JavaDoc request) {
18     ActionErrors actionErrors = null;
19     ArrayList JavaDoc errorList = new ArrayList JavaDoc();
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 JavaDoc request, List JavaDoc errors) {
30   }
31
32   /* Protected Methods */
33
34   protected void addErrorIfStringEmpty(List JavaDoc errors, String JavaDoc message, String JavaDoc value) {
35     if (value == null || value.trim().length() < 1) {
36       errors.add(message);
37     }
38   }
39
40 }
41
Popular Tags