01: /*
02: * $Id: PrepareMultiboxAction.java 471754 2006-11-06 14:55:09Z husted $
03: *
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "License"); you may not use this file except in compliance
10: * with the License. You may obtain a copy of the License at
11: *
12: * http://www.apache.org/licenses/LICENSE-2.0
13: *
14: * Unless required by applicable law or agreed to in writing,
15: * software distributed under the License is distributed on an
16: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17: * KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations
19: * under the License.
20: */
21:
22: package examples.multibox;
23:
24: import javax.servlet.http.HttpServletRequest;
25: import javax.servlet.http.HttpServletResponse;
26:
27: import org.apache.struts.action.Action;
28: import org.apache.struts.action.ActionForm;
29: import org.apache.struts.action.ActionForward;
30: import org.apache.struts.action.ActionMapping;
31:
32: /**
33: * Perform any tasks and setup any data that
34: * must be prepared before the form is displayed.
35: *
36: * @version $Rev: 471754 $ $Date: 2006-11-06 08:55:09 -0600 (Mon, 06 Nov 2006) $
37: */
38: public class PrepareMultiboxAction extends Action {
39:
40: // ------------------------------------------------------------ Constructors
41:
42: /**
43: * Constructor for PrepareOptionsAction.
44: */
45: public PrepareMultiboxAction() {
46: super ();
47: }
48:
49: // ---------------------------------------------------------- Action Methods
50:
51: /**
52: * Process the request and return an <code>ActionForward</code> instance
53: * describing where and how control should be forwarded, or
54: * <code>null</code>if the response has already been completed.
55: *
56: * @param mapping The ActionMapping used to select this instance
57: * @param form The optional ActionForm bean for this request (if any)
58: * @param request The HTTP request we are processing
59: * @param response The HTTP response we are creating
60: *
61: * @exception Exception if an exception occurs
62: *
63: * @return the ActionForward to forward control to
64: */
65: public ActionForward execute(ActionMapping mapping,
66: ActionForm form, HttpServletRequest request,
67: HttpServletResponse response) 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 = { "Red", "Orange", "Yellow", "Green", "Blue",
76: "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: }
|