1 /* 2 * $Id$ 3 * 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "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 jakarta.servlet.http.HttpServletRequest; 25 import jakarta.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$ $Date$ 37 */ 38 public class PrepareMultiboxAction extends Action { 39 private static final long serialVersionUID = 5055393276157457523L; 40 41 // ------------------------------------------------------------ Constructors 42 43 /** 44 * Constructor for PrepareOptionsAction. 45 */ 46 public PrepareMultiboxAction() { 47 super(); 48 } 49 50 // ---------------------------------------------------------- Action Methods 51 52 /** 53 * Process the request and return an <code>ActionForward</code> instance 54 * describing where and how control should be forwarded, or 55 * <code>null</code>if the response has already been completed. 56 * 57 * @param mapping The ActionMapping used to select this instance 58 * @param form The optional ActionForm bean for this request (if any) 59 * @param request The HTTP request we are processing 60 * @param response The HTTP response we are creating 61 * 62 * @exception Exception if an exception occurs 63 * 64 * @return the ActionForward to forward control to 65 */ 66 public ActionForward execute( 67 ActionMapping mapping, 68 ActionForm form, 69 HttpServletRequest request, 70 HttpServletResponse response) 71 throws Exception { 72 73 System.out.println("Prepare MultiboxActionForm ...."); 74 75 /* 76 * Prepare a String array of color names used to generate 77 * checkboxes using html:multibox tags in the JSP page. 78 */ 79 String[] colors = 80 { "Red", "Orange", "Yellow", "Green", "Blue", "Indigo", "Violet" }; 81 request.setAttribute("colors", colors); 82 83 /* 84 * Set default checkbox values. 85 */ 86 String[] defaultFruits = { "Orange", "Banana", "Apple" }; 87 String[] defaultColors = { "Orange", "Yellow" }; 88 MultiboxActionForm multiboxForm = (MultiboxActionForm) form; 89 multiboxForm.setFruits(defaultFruits); 90 multiboxForm.setColors(defaultColors); 91 92 // Return an ActionForward to the form 93 return mapping.findForward("success"); 94 } 95 }