KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > webapp > tiles > dynPortal > SetPortalPrefsAction


1 /*
2  * $Id: SetPortalPrefsAction.java 54929 2004-10-16 16:38:42Z germuska $
3  *
4  * Copyright 1999-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.tiles.dynPortal;
20
21 import javax.servlet.ServletException JavaDoc;
22 import javax.servlet.http.HttpServletRequest JavaDoc;
23 import javax.servlet.http.HttpServletResponse JavaDoc;
24 import javax.servlet.http.HttpSession JavaDoc;
25 import org.apache.struts.action.Action;
26 import org.apache.struts.action.ActionForm;
27 import org.apache.struts.action.ActionForward;
28 import org.apache.struts.action.ActionMapping;
29 import org.apache.struts.tiles.ComponentContext;
30
31
32 /**
33  * Implementation of <strong>Action</strong> that populates an instance of
34  * <code>SubscriptionForm</code> from the currently specified subscription.
35  *
36  * @version $Rev: 54929 $ $Date: 2004-10-16 17:38:42 +0100 (Sat, 16 Oct 2004) $
37  */

38
39 public final class SetPortalPrefsAction extends Action {
40
41
42     // --------------------------------------------------------- Public Methods
43

44
45     /**
46      * Process the specified HTTP request, and create the corresponding HTTP
47      * response (or forward to another web component that will create it).
48      * Return an <code>ActionForward</code> instance describing where and how
49      * control should be forwarded, or <code>null</code> if the response has
50      * already been completed.
51      *
52      * @param mapping The ActionMapping used to select this instance
53      * @param actionForm The optional ActionForm bean for this request (if any)
54      * @param request The HTTP request we are processing
55      * @param response The HTTP response we are creating
56      *
57      * @exception Exception if the application business logic throws
58      * an exception
59      */

60     public ActionForward execute(
61                  ActionMapping mapping,
62                  ActionForm form,
63                  HttpServletRequest JavaDoc request,
64                  HttpServletResponse JavaDoc response)
65     throws Exception JavaDoc
66     {
67     System.out.println("Enter action SetPortalPrefsAction");
68     HttpSession JavaDoc session = request.getSession();
69   PortalPrefsForm prefsForm = (PortalPrefsForm)form;
70
71           // Try to retrieve tile context
72
ComponentContext context = ComponentContext.getContext( request );
73     if( context == null )
74       {
75       throw new ServletException JavaDoc( "This action must be called by a Tile, not directly" );
76       }
77
78       // Get user portal list from user context
79
PortalSettings settings = RetrievePortalAction.getSettings( context, session );
80
81   if( prefsForm.isSubmitted() )
82     { // read arrays
83
System.out.println("form submitted");
84
85       // Set settings cols according to user choice
86
for( int i=0;i<prefsForm.getNumCol(); i++)
87       {
88       settings.resetListAt( i, prefsForm.getNewCol(i));
89       } // end loop
90

91
92     //settings.resetListAt( 0, prefsForm.getL0());
93
//settings.resetListAt( 1, prefsForm.getL1());
94
prefsForm.reset();
95       return (mapping.findForward("portal"));
96     }
97
98       // Set lists values to be shown
99
for( int i=0;i<settings.getNumCols(); i++ )
100       {
101       prefsForm.addCol(settings.getListAt(i) );
102       prefsForm.addColLabels(settings.getListLabelAt(i) );
103       } // end loop
104

105     prefsForm.setChoices(settings.getChoices() );
106     prefsForm.setChoiceLabels(settings.getChoiceLabels() );
107
108     System.out.println("Exit action SetPortalPrefsAction");
109       return (mapping.findForward("preferences"));
110     }
111
112
113 }
114
Popular Tags