From: Chad B. <cwb...@us...> - 2008-07-09 19:49:34
|
User: cwbrandon Date: 08/07/09 12:49:40 Modified: andromda-jsf2/src/main/resources/templates/jsf2/utils/portlet GenericFaceletsPortlet.java.vsl Log: remove the viewId from the session if the session is invalid Revision Changes Path 1.2 +7 -1 cartridges/andromda-jsf2/src/main/resources/templates/jsf2/utils/portlet/GenericFaceletsPortlet.java.vsl Index: GenericFaceletsPortlet.java.vsl =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-jsf2/src/main/resources/templates/jsf2/utils/portlet/GenericFaceletsPortlet.java.vsl,v retrieving revision 1.1 retrieving revision 1.2 diff -u -w -r1.1 -r1.2 --- GenericFaceletsPortlet.java.vsl 18 Apr 2008 21:25:11 -0000 1.1 +++ GenericFaceletsPortlet.java.vsl 9 Jul 2008 19:49:40 -0000 1.2 @@ -182,7 +182,13 @@ // This here below is what was in the MyFacesGenericPortlet implementation // String viewId = request.getParameter(VIEW_ID); - if (viewId == null || sessionInvalidated(request)) + final boolean sessionInvalidated = sessionInvalidated(request); + if (sessionInvalidated) + { + // - remove the view id so we aren't attempting to go back to it if the session is invalid + request.getPortletSession().removeAttribute(VIEW_ID); + } + if (viewId == null || sessionInvalidated) { setPortletRequestFlag(request); nonFacesRequest(request, response); |
From: Chad B. <cwb...@us...> - 2008-07-10 20:15:44
|
User: cwbrandon Date: 08/07/10 13:15:54 Modified: andromda-jsf2/src/main/resources/templates/jsf2/flow/portlet PortletPhaseListener.java.vsl andromda-jsf2/src/main/resources/templates/jsf2/utils/portlet GenericFaceletsPortlet.java.vsl Log: Make sure we stay on the default page when the session expires (even on refreshes) Revision Changes Path 1.18 +8 -0 cartridges/andromda-jsf2/src/main/resources/templates/jsf2/flow/portlet/PortletPhaseListener.java.vsl Index: PortletPhaseListener.java.vsl =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-jsf2/src/main/resources/templates/jsf2/flow/portlet/PortletPhaseListener.java.vsl,v retrieving revision 1.17 retrieving revision 1.18 diff -u -w -r1.17 -r1.18 --- PortletPhaseListener.java.vsl 7 Jul 2008 18:21:48 -0000 1.17 +++ PortletPhaseListener.java.vsl 10 Jul 2008 20:15:53 -0000 1.18 @@ -52,6 +52,14 @@ } } #end + // - remove the stored current view from the session so that the portlet knows it can use + // the default viewId already stored (otherwise it will use the viewId stored in the CURRENT_VIEW) + if (!(javax.faces.event.PhaseId.RESTORE_VIEW.equals(event.getPhaseId()) || + javax.faces.event.PhaseId.RENDER_RESPONSE.equals(event.getPhaseId()))) + { + request.getPortletSession().removeAttribute(${managedBeansPackage}.GenericFaceletsPortlet.CURRENT_VIEW_ID); + } + // - make the faces context available to all views ((javax.portlet.PortletRequest)event.getFacesContext().getExternalContext().getRequest()).setAttribute(FACES_CONTEXT, event.getFacesContext()); 1.3 +30 -11 cartridges/andromda-jsf2/src/main/resources/templates/jsf2/utils/portlet/GenericFaceletsPortlet.java.vsl Index: GenericFaceletsPortlet.java.vsl =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-jsf2/src/main/resources/templates/jsf2/utils/portlet/GenericFaceletsPortlet.java.vsl,v retrieving revision 1.2 retrieving revision 1.3 diff -u -w -r1.2 -r1.3 --- GenericFaceletsPortlet.java.vsl 9 Jul 2008 19:49:40 -0000 1.2 +++ GenericFaceletsPortlet.java.vsl 10 Jul 2008 20:15:54 -0000 1.3 @@ -24,7 +24,8 @@ /** * Extends the default {@link org.apache.myfaces.portlet.MyFacesGenericPortlet} instance to - * provide the necessary support for Facelets. + * provide the necessary support for Facelets. This class depends on the execution + * of {@link PortletPhaseListener}. * * @author Raymond Auge * @author Joel Kozikowski @@ -119,8 +120,8 @@ /** * Overriden in order to save the VIEW_ID to the portlet session (the version in MyFacesGenericPortlet saves the - * viewId as a render parameter which is lost when executing another portlet). This should be fixed at some point - * in the {@link org.apache.myfaces.portlet.MyFacesGenericPortlet} code at which time this method can be removed. + * viewId as a render parameter which is lost when executing another portlet). This method also makes sure + * we stay on the default view once the session becomes invalided (even on refreshes). */ @Override public void processAction(ActionRequest request, ActionResponse response) @@ -136,6 +137,14 @@ { lifecycle.execute(facesContext); + // - get and set the current view explicitly if its set (so that when page refreshes occur + // we stay on the same page). + final String currentView = (String)request.getPortletSession().getAttribute(CURRENT_VIEW_ID); + if (currentView != null) + { + facesContext.getViewRoot().setViewId(currentView); + } + if (!facesContext.getResponseComplete()) { request.getPortletSession().setAttribute(VIEW_ID, facesContext.getViewRoot().getViewId()); @@ -157,10 +166,13 @@ } /** + * Stores the current view id in the session. + */ + public static final String CURRENT_VIEW_ID = GenericFaceletsPortlet.class.getName() + "_CurrentViewId"; + + /** * Overridden in order to retrieve the VIEW_ID from the portlet session (instead of request.getParameter(VIEW_ID) - * as found in {@link org.apache.myfaces.portlet.MyFacesGenericPortlet}). When stored in the request, the VIEW_ID - * is lost when executing anything on another portlet instance. This should be fixed at some point - * in the {@link org.apache.myfaces.portlet.MyFacesGenericPortlet} code at which time this method can be removed. + * as found in {@link org.apache.myfaces.portlet.MyFacesGenericPortlet}). */ @Override protected void facesRender(RenderRequest request, RenderResponse response) @@ -180,27 +192,34 @@ restoreRequired = false; } + setPortletRequestFlag(request); + // This here below is what was in the MyFacesGenericPortlet implementation // String viewId = request.getParameter(VIEW_ID); final boolean sessionInvalidated = sessionInvalidated(request); if (sessionInvalidated) { + // - set the viewId to the default so that we are sent to the default view + viewId = this.defaultView; // - remove the view id so we aren't attempting to go back to it if the session is invalid request.getPortletSession().removeAttribute(VIEW_ID); } + + if (viewId != null) + { + request.getPortletSession().setAttribute(CURRENT_VIEW_ID, viewId); + } + if (viewId == null || sessionInvalidated) { - setPortletRequestFlag(request); nonFacesRequest(request, response); return; } - setPortletRequestFlag(request); - - ServletFacesContextImpl facesContext = null; try { - facesContext = (ServletFacesContextImpl)request.getPortletSession().getAttribute(CURRENT_FACES_CONTEXT); + ServletFacesContextImpl facesContext = (ServletFacesContextImpl) + request.getPortletSession().getAttribute(CURRENT_FACES_CONTEXT); if (facesContext == null) // processAction was not called { facesContext = (ServletFacesContextImpl)facesContext(request, response); |