1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package com.finalist.util.genelv.struts;
19
20 import org.apache.log4j.Category;
21 import org.apache.struts.action.ActionErrors;
22 import org.apache.struts.action.ActionMapping;
23 import org.apache.struts.validator.ValidatorForm;
24
25 import javax.servlet.http.HttpServletRequest;
26
27 /***
28 * Generic form bean
29 *
30 * @author Gerard van de Weerd
31 * @version $1.00$
32 */
33
34 public abstract class GenericForm extends ValidatorForm {
35 static Category log = Category.getInstance(GenericForm.class);
36
37 private Throwable raisedException;
38
39
40 /*** */
41 public Throwable getRaisedException() {
42 return this.raisedException;
43 }
44
45
46
47 private String submit;
48
49
50 /***
51 * Return the value of the submit button
52 */
53 public String getSubmit() {
54 return this.submit;
55 }
56
57
58 /***
59 * Sets the value of the submit.
60 */
61 public void setSubmit(String submit) {
62 this.submit = submit;
63 }
64
65
66 /***
67 * Generic validation with exception handling. Validate the properties that have been set
68 * from this HTTP request,
69 * and return an <code>ActionErrors</code> object that encapsulates any
70 * validation errors that have been found. If no errors are found, return
71 * <code>null</code> or an <code>ActionErrors</code> object with no
72 * recorded error messages.
73 *
74 * @param mapping The mapping used to select this instance
75 * @param request The servlet request we are processing
76 *
77 */
78 public final ActionErrors validate(ActionMapping mapping,
79 HttpServletRequest request) {
80 try {
81 return doValidate(mapping, request);
82 }
83 catch (Throwable t) {
84 this.raisedException = t;
85 return null;
86 }
87 }
88
89
90 /***
91 * Performs the default server-side validation (calls superclass ValidationForm's validate method).
92 * May be overridden by subclasses if custom validation is required within the GenericExceptions framework.
93 *
94 * @param mapping The mapping used to select this instance
95 * @param request The servlet request we are processing
96 * @return an ActionErrors object containing any validation errors, may be <code>null</code>.
97 * @throws Exception - any Throwable exception will be handled by the GenericExceptions framework.
98 */
99 protected ActionErrors doValidate(ActionMapping mapping, HttpServletRequest request) throws Exception {
100 return super.validate(mapping, request);
101 }
102
103 }