1 18 19 package org.apache.struts.webapp.tiles.dynPortal; 20 21 import java.util.List ; 22 import javax.servlet.ServletException ; 23 import javax.servlet.http.HttpServletRequest ; 24 import javax.servlet.http.HttpServletResponse ; 25 import javax.servlet.http.HttpSession ; 26 import org.apache.struts.action.Action; 27 import org.apache.struts.action.ActionForm; 28 import org.apache.struts.action.ActionForward; 29 import org.apache.struts.action.ActionMapping; 30 import org.apache.struts.tiles.ComponentContext; 31 32 33 38 39 public final class RetrievePortalAction extends Action { 40 41 42 public static String USER_PORTAL_SETTINGS = "DynamicPortal.USER_PORTAL_SETTINGS"; 43 44 public static String PARAM_NUMCOLS = "numCols"; 45 46 public static String PARAM_LIST = "list"; 47 48 public static String PARAM_LIST_LABELS = "listLabels"; 49 51 52 67 public ActionForward execute( 68 ActionMapping mapping, 69 ActionForm form, 70 HttpServletRequest request, 71 HttpServletResponse response) 72 throws Exception { 73 System.out.println("Enter action RetrievePortalAction"); 74 HttpSession session = request.getSession(); 76 77 ComponentContext context = ComponentContext.getContext( request ); 79 if( context == null ) 80 { 81 throw new ServletException ( "This action must be called by a Tile, not directly" ); 82 } 83 84 PortalSettings settings = getSettings( context, session ); 86 87 context.putAttribute( "numCols", Integer.toString(settings.getNumCols()) ); 89 for( int i=0; i<settings.getNumCols(); i++ ) 90 context.putAttribute( "list"+i, settings.getListAt(i) ); 91 92 System.out.println("Exit action RetrievePortalAction"); 93 return (mapping.findForward("success")); 94 } 95 96 100 public static PortalSettings getSettings( ComponentContext context, HttpSession session ) 101 { 102 PortalSettings settings = (PortalSettings)session.getAttribute( USER_PORTAL_SETTINGS ); 104 105 if( settings == null ) 106 { settings = new PortalSettings(); 108 settings.setNumCols( (String )context.getAttribute( PARAM_NUMCOLS ) ); 109 for( int i=0; i<settings.getNumCols(); i++ ) 110 { 111 List col = (List )context.getAttribute( ((String )PARAM_LIST+i) ); 112 List labels = (List )context.getAttribute( ((String )PARAM_LIST_LABELS+i) ); 113 settings.addChoices( col, labels ); 114 settings.addList( col ); 115 } 117 session.setAttribute( USER_PORTAL_SETTINGS, settings); 119 } 121 return settings; 122 } 123 124 125 } 126 127 | Popular Tags |