001: /*
002: * $Id: PrepareLogicAction.java 471754 2006-11-06 14:55:09Z husted $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021:
022: package examples.logic;
023:
024: import java.util.ArrayList;
025:
026: import javax.servlet.http.HttpServletRequest;
027: import javax.servlet.http.HttpServletResponse;
028:
029: import org.apache.struts.action.Action;
030: import org.apache.struts.action.ActionErrors;
031: import org.apache.struts.action.ActionForm;
032: import org.apache.struts.action.ActionForward;
033: import org.apache.struts.action.ActionMapping;
034: import org.apache.struts.action.ActionMessage;
035: import org.apache.struts.action.ActionMessages;
036:
037: import examples.TestBean;
038: import examples.options.BookBean;
039:
040: /**
041: * Perform any tasks and setup any data that
042: * must be prepared before the form is displayed.
043: *
044: * @version $Rev: 471754 $ $Date: 2006-11-06 08:55:09 -0600 (Mon, 06 Nov 2006) $
045: */
046: public class PrepareLogicAction extends Action {
047:
048: // ------------------------------------------------------------ Constructors
049:
050: /**
051: * Constructor for PrepareOptionsAction.
052: */
053: public PrepareLogicAction() {
054: super ();
055: }
056:
057: // ---------------------------------------------------------- Action Methods
058:
059: /**
060: * Process the request and return an <code>ActionForward</code> instance
061: * describing where and how control should be forwarded, or
062: * <code>null</code>if the response has already been completed.
063: *
064: * @param mapping The ActionMapping used to select this instance
065: * @param form The optional ActionForm bean for this request (if any)
066: * @param request The HTTP request we are processing
067: * @param response The HTTP response we are creating
068: *
069: * @exception Exception if an exception occurs
070: *
071: * @return the ActionForward to forward control to
072: */
073: public ActionForward execute(ActionMapping mapping,
074: ActionForm form, HttpServletRequest request,
075: HttpServletResponse response) throws Exception {
076:
077: TestBean bean = new TestBean();
078: request.setAttribute("testBean", bean);
079:
080: ArrayList items = new ArrayList();
081: request.setAttribute("items", items);
082:
083: request.setAttribute("intValue", new Integer(7));
084: request.setAttribute("stringValue", "Hello, world!");
085:
086: /* Collection of custom beans */
087: ArrayList books = new ArrayList();
088: books.add(new BookBean("0596003285",
089: "Programming Jakarta Struts"));
090: books.add(new BookBean("1930110502", "Struts in Action"));
091: books.add(new BookBean("1861007817",
092: "Professional Struts Applications"));
093: books.add(new BookBean("0672324725", "Struts Kick Start"));
094: books
095: .add(new BookBean("0471213020",
096: "Mastering Jakarta Struts"));
097: books.add(new BookBean("1558608621", "The Struts Framework"));
098: books.add(new BookBean("0971661901", "Struts Fast Track"));
099: request.setAttribute("books", books);
100:
101: ActionErrors errors = new ActionErrors();
102:
103: errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
104: "errors.detail", "This is a global error #1"));
105: errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
106: "errors.detail", "This is a global error #2"));
107: errors.add("test", new ActionMessage("errors.detail",
108: "This is a test error"));
109:
110: ActionMessages messages = new ActionMessages();
111: messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
112: "message.detail", "This is global message #1"));
113: messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
114: "message.detail", "This is global message #2"));
115: messages.add("test",
116: new ActionMessage("message.example.simple"));
117:
118: saveMessages(request, messages);
119: saveErrors(request, errors);
120:
121: // Forward to the form
122: return mapping.findForward("success");
123:
124: }
125:
126: }
|