View Javadoc

1   /*
2    * $Id: MultiboxActionForm.java 421486 2006-07-13 03:37:08Z wsmoak $
3    *
4    * Copyright 2005 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package examples.multibox;
20  
21  import javax.servlet.http.HttpServletRequest;
22  
23  import org.apache.struts.action.ActionErrors;
24  import org.apache.struts.action.ActionForm;
25  import org.apache.struts.action.ActionMapping;
26  
27  /***
28   * An ActionForm for the Multibox examples
29   *
30   * @version $Rev: 421486 $ $Date: 2006-07-12 20:37:08 -0700 (Wed, 12 Jul 2006) $
31   */
32  public class MultiboxActionForm extends ActionForm {
33  
34      // ------------------------------------------------------ Instance Variables
35  
36      /*** Fruits */
37      private String[] fruits = {};
38  
39      /*** Colors */
40      private String[] colors = {};
41  
42      // ------------------------------------------------------------ Constructors
43  
44      /***
45       * Constructor for MultiboxActionForm.
46       */
47      public MultiboxActionForm() {
48          super();
49      }
50  
51      // ---------------------------------------------------------- Public Methods
52  
53      /***
54       * Clear all checkboxes
55       *
56       * @param mapping The mapping used to select this instance
57       * @param request The servlet request we are processing
58       */
59      public void reset(ActionMapping mapping, HttpServletRequest request) {
60  
61          /*
62           * The ActionForm reset method should only be used to *clear*
63           * checkboxes. The correct place to *set* default checkbox values is in
64           * the 'prepare' action, called prior to displaying the form page.
65           */
66          String[] empty = {};
67          this.fruits = empty;
68          this.colors = empty;
69  
70      }
71  
72      /***
73       * Validate the properties that have been set from this HTTP request,
74       * and return an <code>ActionMessages</code> object that encapsulates any
75       * validation errors that have been found.  If no errors are found, return
76       * <code>null</code> or an <code>ActionMessages</code> object with no
77       * recorded error messages.
78       *
79       * @param mapping The mapping used to select this instance
80       * @param request The servlet request we are processing
81       *
82       * @return ActionMessages if any validation errors occurred
83       */
84      public ActionErrors validate(
85          ActionMapping mapping,
86          HttpServletRequest request) {
87  
88          /*
89           * We're not doing any validation (yet) so return null to
90           * indicate that there were no errors. (We don't
91           * actually need to override this nethod unles we're doing
92           * validation - but it's here for reference)
93           */
94          return null;
95      }
96  
97      // -------------------------------------------------------------- Properties
98  
99      /***
100      * Returns the colors.
101      * @return String[]
102      */
103     public String[] getColors() {
104         return colors;
105     }
106 
107     /***
108      * Returns the fruits.
109      * @return String[]
110      */
111     public String[] getFruits() {
112         return fruits;
113     }
114 
115     /***
116      * Sets the colors.
117      * @param colors The colors to set
118      */
119     public void setColors(String[] colors) {
120         this.colors = colors;
121     }
122 
123     /***
124      * Sets the fruits.
125      * @param fruits The fruits to set
126      */
127     public void setFruits(String[] fruits) {
128         this.fruits = fruits;
129     }
130 
131 }