1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package examples.options;
20
21 import java.util.ArrayList;
22 import java.util.HashMap;
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 import org.apache.struts.util.LabelValueBean;
32
33 /***
34 * Perform any tasks and setup any data that
35 * must be prepared before the form is displayed.
36 *
37 * @version $Rev: 421486 $ $Date: 2006-07-12 20:37:08 -0700 (Wed, 12 Jul 2006) $
38 */
39 public class PrepareOptionsAction extends Action {
40
41
42
43 /***
44 * Constructor for PrepareOptionsAction.
45 */
46 public PrepareOptionsAction() {
47 super();
48 }
49
50
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
74 String[] fruits =
75 {
76 "Strawberry",
77 "Apple",
78 "Orange",
79 "Pear",
80 "Mango",
81 "Banana",
82 "Pineapple" };
83 request.setAttribute("fruits", fruits);
84
85
86 String[] colors =
87 { "Red", "Orange", "Yellow", "Green", "Blue", "Indigo", "Violet" };
88 request.setAttribute("colors", colors);
89
90 String[] colorCodes =
91 {
92 "#FF0000",
93 "#FFA500",
94 "#FFFF00",
95 "#00FF00",
96 "#0000FF",
97 "#4B0082",
98 "#EE82EE" };
99 request.setAttribute("colorCodes", colorCodes);
100
101
102 ArrayList colorList = new ArrayList();
103 colorList.add("Red");
104 colorList.add("Orange");
105 colorList.add("Yellow");
106 colorList.add("Green");
107 colorList.add("Blue");
108 colorList.add("Indigo");
109 colorList.add("Violet");
110 request.setAttribute("colorCollection", colorList);
111
112
113 ArrayList days = new ArrayList();
114 days.add(new LabelValueBean("Monday", "1"));
115 days.add(new LabelValueBean("Tuesday", "2"));
116 days.add(new LabelValueBean("Wednesday", "3"));
117 days.add(new LabelValueBean("Thursday", "4"));
118 days.add(new LabelValueBean("Friday", "5"));
119 days.add(new LabelValueBean("Saturday", "6"));
120 days.add(new LabelValueBean("Sunday", "7"));
121 request.setAttribute("days", days);
122
123
124 ArrayList books = new ArrayList();
125 books.add(new BookBean("0596003285", "Programming Jakarta Struts"));
126 books.add(new BookBean("1930110502", "Struts in Action"));
127 books.add(
128 new BookBean("1861007817", "Professional Struts Applications"));
129 books.add(new BookBean("0672324725", "Struts Kick Start"));
130 books.add(new BookBean("0471213020", "Mastering Jakarta Struts"));
131 books.add(new BookBean("1558608621", "The Struts Framework"));
132 books.add(new BookBean("0971661901", "Struts Fast Track"));
133 request.setAttribute("books", books);
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149 HashMap animals = new HashMap();
150 animals.put(new Integer(1), "Cat");
151 animals.put(new Integer(2), "Dog");
152 animals.put(new Integer(3), "Horse");
153 animals.put(new Integer(4), "Rabbit");
154 animals.put(new Integer(5), "Goldfish");
155 request.setAttribute("animals", animals);
156
157
158 return mapping.findForward("success");
159
160 }
161
162 }