View Javadoc

1   /*   Copyright (C) 2004 Finalist IT Group
2    *
3    *   This file is part of JAG - the Java J2EE Application Generator
4    *
5    *   JAG is free software; you can redistribute it and/or modify
6    *   it under the terms of the GNU General Public License as published by
7    *   the Free Software Foundation; either version 2 of the License, or
8    *   (at your option) any later version.
9    *   JAG is distributed in the hope that it will be useful,
10   *   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   *   GNU General Public License for more details.
13   *   You should have received a copy of the GNU General Public License
14   *   along with JAG; if not, write to the Free Software
15   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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     // the submitbutton
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 }