View Javadoc

1   /*
2    * $Id: PrepareMultiboxAction.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  import javax.servlet.http.HttpServletResponse;
23  
24  import org.apache.struts.action.Action;
25  import org.apache.struts.action.ActionForm;
26  import org.apache.struts.action.ActionForward;
27  import org.apache.struts.action.ActionMapping;
28  
29  /***
30   * Perform any tasks and setup any data that
31   * must be prepared before the form is displayed.
32   *
33   * @version $Rev: 421486 $ $Date: 2006-07-12 20:37:08 -0700 (Wed, 12 Jul 2006) $
34   */
35  public class PrepareMultiboxAction extends Action {
36  
37      // ------------------------------------------------------------ Constructors
38  
39      /***
40       * Constructor for PrepareOptionsAction.
41       */
42      public PrepareMultiboxAction() {
43          super();
44      }
45  
46      // ---------------------------------------------------------- Action Methods
47  
48      /***
49       * Process the request and return an <code>ActionForward</code> instance
50       * describing where and how control should be forwarded, or
51       * <code>null</code>if the response has already been completed.
52       *
53       * @param mapping The ActionMapping used to select this instance
54       * @param form The optional ActionForm bean for this request (if any)
55       * @param request The HTTP request we are processing
56       * @param response The HTTP response we are creating
57       *
58       * @exception Exception if an exception occurs
59       *
60       * @return the ActionForward to forward control to
61       */
62      public ActionForward execute(
63          ActionMapping mapping,
64          ActionForm form,
65          HttpServletRequest request,
66          HttpServletResponse response)
67          throws Exception {
68  
69          System.out.println("Prepare MultiboxActionForm ....");
70  
71          /*
72           * Prepare a String array of color names used to generate
73           * checkboxes using html:multibox tags in the JSP page.
74           */
75          String[] colors =
76              { "Red", "Orange", "Yellow", "Green", "Blue", "Indigo", "Violet" };
77          request.setAttribute("colors", colors);
78  
79          /*
80           * Set default checkbox values.
81           */
82          String[] defaultFruits = { "Orange", "Banana", "Apple" };
83          String[] defaultColors = { "Orange", "Yellow" };
84          MultiboxActionForm multiboxForm = (MultiboxActionForm) form;
85          multiboxForm.setFruits(defaultFruits);
86          multiboxForm.setColors(defaultColors);
87  
88          // Return an ActionForward to the form
89          return mapping.findForward("success");
90  
91      }
92  
93  }