View Javadoc

1   /*
2    * $Id: EditTypeAction.java 421488 2006-07-13 03:43:08Z wsmoak $
3    *
4    * Copyright 2000-2004 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 org.apache.struts.webapp.validator;
20  
21  import javax.servlet.http.HttpServletRequest;
22  import javax.servlet.http.HttpServletResponse;
23  
24  import java.util.ArrayList;
25  import org.apache.commons.logging.Log;
26  import org.apache.commons.logging.LogFactory;
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   * Initializes ActionForm.
35   *
36   */
37  public final class EditTypeAction extends Action {
38  
39      /***
40       * Commons Logging instance.
41       */
42      private Log log = LogFactory.getFactory().getInstance(this.getClass().getName());
43  
44      /***
45       * Process the specified HTTP request, and create the corresponding HTTP
46       * response (or forward to another web component that will create it).
47       * Return an <code>ActionForward</code> instance describing where and how
48       * control should be forwarded, or <code>null</code> if the response has
49       * already been completed.
50       *
51       * @param mapping The ActionMapping used to select this instance
52       * @param form The optional ActionForm bean for this request (if any)
53       * @param request The HTTP request we are processing
54       * @param response The HTTP response we are creating
55       *
56       * @return Action to forward to
57       * @exception Exception if an input/output error or servlet exception occurs
58       */
59      public ActionForward execute(
60              ActionMapping mapping,
61              ActionForm form,
62              HttpServletRequest request,
63              HttpServletResponse response)
64              throws Exception {
65  
66          // Was this transaction cancelled?
67  
68          initFormBeans(mapping, form, request);
69  
70          return mapping.findForward("success");
71      }
72  
73      /***
74       * Convenience method for initializing form bean.
75       * @param mapping The ActionMapping used to select this instance
76       * @param request The HTTP request we are processing
77       */
78      protected void initFormBeans(
79              ActionMapping mapping, ActionForm form,
80              HttpServletRequest request) {
81  
82          log.debug("initFromBeans");
83  
84          // Initialize
85          ArrayList satisfactionList = new ArrayList();
86          satisfactionList.add(new LabelValueBean("Very Satisfied", "4"));
87          satisfactionList.add(new LabelValueBean("Satisfied", "3"));
88          satisfactionList.add(new LabelValueBean("Not Very Satisfied", "2"));
89          satisfactionList.add(new LabelValueBean("Not Satisfied", "1"));
90          request.setAttribute("satisfactionList", satisfactionList);
91  
92          ArrayList osTypes = new ArrayList();
93          osTypes.add(new LabelValueBean("Mac OsX", "OsX"));
94          osTypes.add(new LabelValueBean("Windows 95/98/Me", "Win32"));
95          osTypes.add(new LabelValueBean("Windows NT/2000/XP/2003", "WinNT"));
96          osTypes.add(new LabelValueBean("Linux", "Linux"));
97          osTypes.add(new LabelValueBean("BSD NetBSD/FreeBSD/OpenBSD", "BSD"));
98          request.setAttribute("osTypes", osTypes);
99  
100         ArrayList languageTypes = new ArrayList();
101         languageTypes.add(new LabelValueBean("C++", "C++"));
102         languageTypes.add(new LabelValueBean("C#", "C#"));
103         languageTypes.add(new LabelValueBean("Java", "java"));
104         languageTypes.add(new LabelValueBean("Smalltalk", "Smalltalk"));
105         request.setAttribute("languageTypes", languageTypes);
106     }
107 }