Author: taylor
Date: Thu May 17 16:11:41 2007
New Revision: 539158
URL: http://svn.apache.org/viewvc?view=rev&rev=539158
Log:
http://issues.apache.org/jira/browse/PB-7
contribution from Steve Halverson
reviewed FacesMessage code to carry over messages to render phase
Modified:
portals/bridges/trunk/jsf/src/java/org/apache/portals/bridges/jsf/FacesPortlet.java
Modified:
portals/bridges/trunk/jsf/src/java/org/apache/portals/bridges/jsf/FacesPortlet.java
URL:
http://svn.apache.org/viewvc/portals/bridges/trunk/jsf/src/java/org/apache/portals/bridges/jsf/FacesPortlet.java?view=diff&rev=539158&r1=539157&r2=539158
==============================================================================
---
portals/bridges/trunk/jsf/src/java/org/apache/portals/bridges/jsf/FacesPortlet.java
(original)
+++
portals/bridges/trunk/jsf/src/java/org/apache/portals/bridges/jsf/FacesPortlet.java
Thu May 17 16:11:41 2007
@@ -17,10 +17,16 @@
package org.apache.portals.bridges.jsf;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
import javax.faces.FacesException;
import javax.faces.FactoryFinder;
import javax.faces.application.Application;
+import javax.faces.application.FacesMessage;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import javax.faces.context.FacesContextFactory;
@@ -58,27 +64,38 @@
/** The Log instance for this class. */
private static final Log log = LogFactory.getLog(FacesPortlet.class);
- /** The VIEW_ROOT used to keep track of action between the action request
and the render request. */
+ /**
+ * The VIEW_ROOT used to keep track of action between the action request
and
+ * the render request.
+ */
public static final String VIEW_ROOT =
"org.apache.portals.bridges.jsf.VIEW_ROOT";
-
- /**
- * The REQUEST_SERVLET_PATH used for
externalContext.getRequestServletPath(). externalContext.getRequestServletPath()
- * should return null but this is a work around an issue with MyFaces
JspViewHandler implementation getServletMapping().
+
+ /**
+ * The REQUEST_SERVLET_PATH used for
+ * externalContext.getRequestServletPath().
+ * externalContext.getRequestServletPath() should return null but this is a
+ * work around an issue with MyFaces JspViewHandler implementation
+ * getServletMapping().
*/
public static final String REQUEST_SERVLET_PATH =
"org.apache.portals.bridges.jsf.REQUEST_SERVLET_PATH";
/**
- * The REQUEST_TYPE request attribute can be used to determine the Portlet
request type ([EMAIL PROTECTED] #ACTION_REQUEST},
- * [EMAIL PROTECTED] #VIEW_REQUEST}, [EMAIL PROTECTED] #HELP_REQUEST},
[EMAIL PROTECTED] #EDIT_REQUEST} or [EMAIL PROTECTED] #CUSTOM_REQUEST}) of the
current request.
+ * The REQUEST_TYPE request attribute can be used to determine the Portlet
+ * request type ([EMAIL PROTECTED] #ACTION_REQUEST}, [EMAIL PROTECTED]
#VIEW_REQUEST},
+ * [EMAIL PROTECTED] #HELP_REQUEST}, [EMAIL PROTECTED] #EDIT_REQUEST} or
[EMAIL PROTECTED] #CUSTOM_REQUEST})
+ * of the current request.
*/
public static final String REQUEST_TYPE =
"org.apache.portals.bridges.jsf.request_type";
-
+
/** The JSF_VIEW_ID used to maintain the state of the view action. */
public static final String JSF_VIEW_ID = "jsf_viewid";
+
public static final String JSF_EDIT_ID = "jsf_editid";
+
public static final String JSF_HELP_ID = "jsf_helpid";
+
public static final String JSF_CUSTOM_ID = "jsf_customid";
-
+
/** Name of portlet preference for Action page. */
public static final String PARAM_ACTION_PAGE = "ActionPage";
@@ -109,9 +126,12 @@
/** Help request. */
public static final String HELP_REQUEST = "HELP";
+ /** FacesMessage objects on portlet session */
+ public static final String FACES_MESSAGES = "FACES_MESSAGES";
+
/** Override default behavior for Unique IDS */
public static final String PARAM_UNIQUE_IDS = "OverrideUniqueIds";
-
+
/** Default URL for the action page. */
private String defaultActionPage = null;
@@ -128,7 +148,7 @@
private String defaultViewPage = null;
private String uniqueIds = null;
-
+
/**
* <p>
* Context initialization parameter name for the lifecycle identifier of
the
@@ -192,10 +212,11 @@
* Acquire the factory instance we will require.
* </p>
*
- * @exception PortletException if, for any reason, the startp of this Faces
- * application failed. This includes errors in the config
- * file that is parsed before or during the processing of
- * this <code>init()</code> method.
+ * @exception PortletException
+ * if, for any reason, the startp of this Faces application
+ * failed. This includes errors in the config file that is
+ * parsed before or during the processing of this
+ * <code>init()</code> method.
*/
public void init(PortletConfig portletConfig) throws PortletException
{
@@ -213,14 +234,16 @@
this.defaultEditPage = portletConfig.getInitParameter(PARAM_EDIT_PAGE);
this.defaultHelpPage = portletConfig.getInitParameter(PARAM_HELP_PAGE);
this.uniqueIds = portletConfig.getInitParameter(PARAM_UNIQUE_IDS);
-
+
if (null == this.defaultViewPage)
{
// A Faces Portlet is required to have at least the
// defaultViewPage
// defined!
- throw new PortletException("Portlet " +
portletConfig.getPortletName()
- + " is incorrectly configured. No default View page is
defined.");
+ throw new PortletException(
+ "Portlet "
+ + portletConfig.getPortletName()
+ + " is incorrectly configured. No default View
page is defined.");
}
if (null == this.defaultActionPage)
{
@@ -248,67 +271,79 @@
* @see javax.portlet.GenericPortlet#doEdit(javax.portlet.RenderRequest,
* javax.portlet.RenderResponse)
*/
- public void doEdit(RenderRequest request, RenderResponse response) throws
PortletException, IOException
+ public void doEdit(RenderRequest request, RenderResponse response)
+ throws PortletException, IOException
{
- process(request, response, defaultEditPage, FacesPortlet.EDIT_REQUEST,
JSF_EDIT_ID);
+ process(request, response, defaultEditPage, FacesPortlet.EDIT_REQUEST,
+ JSF_EDIT_ID);
}
/**
* @see javax.portlet.GenericPortlet#doHelp(javax.portlet.RenderRequest,
* javax.portlet.RenderResponse)
*/
- public void doHelp(RenderRequest request, RenderResponse response) throws
PortletException, IOException
+ public void doHelp(RenderRequest request, RenderResponse response)
+ throws PortletException, IOException
{
- if (this.defaultHelpPage != null &&
this.defaultHelpPage.endsWith(".html"))
+ if (this.defaultHelpPage != null
+ && this.defaultHelpPage.endsWith(".html"))
{
super.doHelp(request, response);
- }
- else
+ } else
{
- process(request, response, defaultHelpPage,
FacesPortlet.HELP_REQUEST, JSF_HELP_ID);
+ process(request, response, defaultHelpPage,
+ FacesPortlet.HELP_REQUEST, JSF_HELP_ID);
}
}
/**
- * @param request The [EMAIL PROTECTED] RenderRequest}.
- * @param response The [EMAIL PROTECTED] RenderResponse}.
- * @throws PortletException Throws a [EMAIL PROTECTED] PortletException}.
- * @throws IOException Throws a [EMAIL PROTECTED] IOException}.
+ * @param request
+ * The [EMAIL PROTECTED] RenderRequest}.
+ * @param response
+ * The [EMAIL PROTECTED] RenderResponse}.
+ * @throws PortletException
+ * Throws a [EMAIL PROTECTED] PortletException}.
+ * @throws IOException
+ * Throws a [EMAIL PROTECTED] IOException}.
*/
- public void doCustom(RenderRequest request, RenderResponse response)
throws PortletException, IOException
+ public void doCustom(RenderRequest request, RenderResponse response)
+ throws PortletException, IOException
{
- process(request, response, defaultCustomPage,
FacesPortlet.CUSTOM_REQUEST, JSF_CUSTOM_ID);
+ process(request, response, defaultCustomPage,
+ FacesPortlet.CUSTOM_REQUEST, JSF_CUSTOM_ID);
}
/**
* @see javax.portlet.GenericPortlet#doView(javax.portlet.RenderRequest,
* javax.portlet.RenderResponse)
*/
- public void doView(RenderRequest request, RenderResponse response) throws
PortletException, IOException
+ public void doView(RenderRequest request, RenderResponse response)
+ throws PortletException, IOException
{
- process(request, response, defaultViewPage, FacesPortlet.VIEW_REQUEST,
JSF_VIEW_ID);
+ process(request, response, defaultViewPage, FacesPortlet.VIEW_REQUEST,
+ JSF_VIEW_ID);
}
/**
* @see javax.portlet.Portlet#processAction(javax.portlet.ActionRequest,
* javax.portlet.ActionResponse)
*/
- public void processAction(ActionRequest request, ActionResponse response)
throws PortletException, IOException
+ public void processAction(ActionRequest request, ActionResponse response)
+ throws PortletException, IOException
{
String viewId = JSF_CUSTOM_ID;
if (request.getPortletMode().equals(PortletMode.VIEW))
{
- viewId = JSF_VIEW_ID;
- }
- else if (request.getPortletMode().equals(PortletMode.EDIT))
+ viewId = JSF_VIEW_ID;
+ } else if (request.getPortletMode().equals(PortletMode.EDIT))
{
- viewId = JSF_EDIT_ID;
- }
- else if (request.getPortletMode().equals(PortletMode.HELP))
+ viewId = JSF_EDIT_ID;
+ } else if (request.getPortletMode().equals(PortletMode.HELP))
{
- viewId = JSF_HELP_ID;
+ viewId = JSF_HELP_ID;
}
- process(request, response, defaultActionPage,
FacesPortlet.ACTION_REQUEST, viewId);
+ process(request, response, defaultActionPage,
+ FacesPortlet.ACTION_REQUEST, viewId);
}
/**
@@ -317,30 +352,28 @@
* </p>
*
* @return The [EMAIL PROTECTED] FacesContextFactory}.
- * @throws PortletException Throws a [EMAIL PROTECTED] PortletException}.
+ * @throws PortletException
+ * Throws a [EMAIL PROTECTED] PortletException}.
*/
public FacesContextFactory getFacesContextFactory() throws PortletException
{
- if (facesContextFactory != null)
- {
- return facesContextFactory;
- }
+ if (facesContextFactory != null) { return facesContextFactory; }
try
{
- facesContextFactory = (FacesContextFactory)
FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
+ facesContextFactory = (FacesContextFactory) FactoryFinder
+ .getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
if (log.isTraceEnabled())
{
- log.trace("Retrieved facesContextFactory " +
facesContextFactory);
+ log.trace("Retrieved facesContextFactory "
+ + facesContextFactory);
}
- }
- catch (FacesException e)
+ } catch (FacesException e)
{
Throwable rootCause = e.getCause();
if (rootCause == null)
{
throw e;
- }
- else
+ } else
{
throw new PortletException(e.getMessage(), rootCause);
}
@@ -354,14 +387,12 @@
* </p>
*
* @return The [EMAIL PROTECTED] Lifecycle}.
- * @throws PortletException Throws a [EMAIL PROTECTED] PortletException}.
+ * @throws PortletException
+ * Throws a [EMAIL PROTECTED] PortletException}.
*/
public Lifecycle getLifecycle() throws PortletException
{
- if (lifecycle != null)
- {
- return lifecycle;
- }
+ if (lifecycle != null) { return lifecycle; }
try
{
LifecycleFactory lifecycleFactory = (LifecycleFactory)
FactoryFinder
@@ -370,7 +401,8 @@
{
log.trace("Retrieved lifecycleFactory " + lifecycleFactory);
}
- String lifecycleId =
portletConfig.getPortletContext().getInitParameter(LIFECYCLE_ID_ATTR);
+ String lifecycleId = portletConfig.getPortletContext()
+ .getInitParameter(LIFECYCLE_ID_ATTR);
if (log.isDebugEnabled())
{
log.debug("lifecycleId " + lifecycleId);
@@ -382,17 +414,16 @@
lifecycle = lifecycleFactory.getLifecycle(lifecycleId);
if (log.isTraceEnabled())
{
- log.trace("Retrieved lifecycle from lifecycleFactory " +
lifecycle);
+ log.trace("Retrieved lifecycle from lifecycleFactory "
+ + lifecycle);
}
- }
- catch (FacesException e)
+ } catch (FacesException e)
{
Throwable rootCause = e.getCause();
if (rootCause == null)
{
throw e;
- }
- else
+ } else
{
throw new PortletException(e.getMessage(), rootCause);
}
@@ -405,33 +436,41 @@
* Processes the request.
* </p>
*
- * @param request The [EMAIL PROTECTED] PortletRequest}.
- * @param response The [EMAIL PROTECTED] PortletResponse}.
- * @param defaultPage The default page.
- * @param requestType The request type.
- * @throws PortletException Throws a [EMAIL PROTECTED] PortletException}.
- * @throws IOException Throws an [EMAIL PROTECTED] IOException}.
+ * @param request
+ * The [EMAIL PROTECTED] PortletRequest}.
+ * @param response
+ * The [EMAIL PROTECTED] PortletResponse}.
+ * @param defaultPage
+ * The default page.
+ * @param requestType
+ * The request type.
+ * @throws PortletException
+ * Throws a [EMAIL PROTECTED] PortletException}.
+ * @throws IOException
+ * Throws an [EMAIL PROTECTED] IOException}.
*/
- private void process(PortletRequest request, PortletResponse response,
String defaultPage, String requestType, String viewId)
+ private void process(PortletRequest request, PortletResponse response,
+ String defaultPage, String requestType, String viewId)
throws PortletException, IOException
{
boolean actionRequest = ACTION_REQUEST.equals(requestType);
boolean renderRequest = !actionRequest;
-
- request.setAttribute(REQUEST_TYPE, requestType);
-
String defaultView = defaultPage;
-
+
+ request.setAttribute(REQUEST_TYPE, requestType);
+
if (actionRequest)
{
log.trace("Begin FacesPortlet.processAction()");
}
-
+ // remove any lingering JSF attributes
+ cleanUpAfterPortal(request, response);
+
// Acquire the FacesContext instance for this request
FacesContext context = getFacesContextFactory().getFacesContext(
- portletConfig.getPortletContext(),
- request, response, getLifecycle());
+ portletConfig.getPortletContext(), request, response,
+ getLifecycle());
// Restore view if available.
setDefaultView(context, defaultPage, viewId);
@@ -441,7 +480,7 @@
}
preProcessFaces(context);
-
+
// Execute the pre-render request processing lifecycle for this request
try
{
@@ -453,60 +492,67 @@
log.trace("End Executing phases");
}
// The view should have been restore.
- // Pass it to the render request.
-
-
request.getPortletSession().setAttribute(createViewRootKey(context,
defaultPage, viewId), context.getViewRoot());
- ActionResponse actionResponse = (ActionResponse)response;
-
- // actionResponse.setRenderParameter(viewId,
context.getViewRoot().getViewId()); // get the navigation change
- }
- else if (renderRequest)
+ // Pass it to the render request.
+
+ request.getPortletSession().setAttribute(
+ createViewRootKey(context, defaultPage, viewId),
+ context.getViewRoot());
+ ActionResponse actionResponse = (ActionResponse) response;
+
+ // save FacesMessage objects on session; so they can
+ // be restored during the render phase
+ saveFacesMessages(context, request.getPortletSession());
+ } else if (renderRequest)
{
- // getLifecycle().execute(context);
+ // getLifecycle().execute(context);
String vi = context.getViewRoot().getViewId();
- context.getApplication().getViewHandler().restoreView(context,
vi);
-
+ context.getApplication().getViewHandler().restoreView(context,
+ vi);
+
+ // restore FacesMessage objects that were previously
established
+ // in the lifecycle
+ restoreFacesMessages(context, request.getPortletSession());
+
getLifecycle().render(context);
if (log.isTraceEnabled())
{
log.trace("End executing RenderResponse phase ");
}
- }
- else
+ } else
{
- throw new PortletException("Request must be of type
ActionRequest or RenderRequest");
- }
- request.getPortletSession().setAttribute(viewId,
context.getViewRoot().getViewId(), PortletSession.PORTLET_SCOPE);
-
- }
- catch (FacesException e)
+ throw new PortletException(
+ "Request must be of type ActionRequest or
RenderRequest");
+ }
+
+ request.getPortletSession().setAttribute(viewId,
+ context.getViewRoot().getViewId(),
+ PortletSession.PORTLET_SCOPE);
+
+ } catch (FacesException e)
{
Throwable t = ((FacesException) e).getCause();
if (t == null)
{
throw new PortletException(e.getMessage(), e);
- }
- else
+ } else
{
if (t instanceof PortletException)
{
throw ((PortletException) t);
- }
- else if (t instanceof IOException)
+ } else if (t instanceof IOException)
{
throw ((IOException) t);
- }
- else
+ } else
{
throw new PortletException(t.getMessage(), t);
}
}
- }
- finally
+ } finally
{
// Release the FacesContext instance for this request
context.release();
}
+
if (log.isTraceEnabled())
{
log.trace("End FacesPortlet.process()");
@@ -514,16 +560,18 @@
}
protected void preProcessFaces(FacesContext context)
- {
+ {
}
-
-
- private String createViewRootKey(FacesContext context, String defaultView,
String viewId)
+
+ private String createViewRootKey(FacesContext context, String defaultView,
+ String viewId)
{
- PortletRequest portletRequest = (PortletRequest)
context.getExternalContext().getRequest();
+ PortletRequest portletRequest = (PortletRequest) context
+ .getExternalContext().getRequest();
// String view = portletRequest.getParameter(viewId);
- String view =
(String)portletRequest.getPortletSession().getAttribute(viewId,
PortletSession.PORTLET_SCOPE);
-
+ String view = (String) portletRequest.getPortletSession().getAttribute(
+ viewId, PortletSession.PORTLET_SCOPE);
+
if (view == null)
{
view = defaultView;
@@ -532,103 +580,231 @@
UIViewRoot root = context.getViewRoot();
if (root != null)
{
- key = key + ":" + root.getViewId();
- }
- else
+ key = key + ":" + root.getViewId();
+ } else
{
key = key + ":" + view;
}
if (uniqueIds != null)
{
- PortletResponse response =
(PortletResponse)context.getExternalContext().getResponse();
+ PortletResponse response = (PortletResponse) context
+ .getExternalContext().getResponse();
if (!(response instanceof RenderResponse))
{
log.error("Cant encode action response");
- }
- else
+ } else
{
- RenderResponse rr = (RenderResponse)response;
+ RenderResponse rr = (RenderResponse) response;
key = key + rr.getNamespace();
}
}
return key;
}
-
+
/**
* <p>
* Set the view identifier to the view for the page to be rendered.
* </p>
*
- * @param context The [EMAIL PROTECTED] FacesContext}for the current
request.
- * @param defaultView The default view identifier.
+ * @param context
+ * The [EMAIL PROTECTED] FacesContext}for the current request.
+ * @param defaultView
+ * The default view identifier.
* @return The default view.
*/
- private void setDefaultView(FacesContext facesContext, String defaultView,
String viewId)
+ private void setDefaultView(FacesContext facesContext, String defaultView,
+ String viewId)
{
// Need to be able to transport viewId between actionRequest and
// renderRequest.
- PortletRequest portletRequest = (PortletRequest)
facesContext.getExternalContext().getRequest();
+ PortletRequest portletRequest = (PortletRequest) facesContext
+ .getExternalContext().getRequest();
if (portletRequest instanceof ActionRequest)
{
- String view =
(String)portletRequest.getPortletSession().getAttribute(viewId,
PortletSession.PORTLET_SCOPE);
-
- if ((null != facesContext.getViewRoot()) && (null !=
facesContext.getViewRoot().getViewId()))
+ String view = (String) portletRequest.getPortletSession()
+ .getAttribute(viewId, PortletSession.PORTLET_SCOPE);
+
+ if ((null != facesContext.getViewRoot())
+ && (null != facesContext.getViewRoot().getViewId()))
{
defaultView = facesContext.getViewRoot().getViewId();
}
- //else if (null != portletRequest.getParameter(viewId))
+ // else if (null != portletRequest.getParameter(viewId))
else if (null != view)
{
- //defaultView = portletRequest.getParameter(viewId);
+ // defaultView = portletRequest.getParameter(viewId);
defaultView = view;
}
-
- UIViewRoot viewRoot = (UIViewRoot)portletRequest.
- getPortletSession().
-
getAttribute(createViewRootKey(facesContext, defaultView, viewId));
+
+ UIViewRoot viewRoot = (UIViewRoot) portletRequest
+ .getPortletSession()
+ .getAttribute(
+ createViewRootKey(facesContext, defaultView,
viewId));
if (viewRoot != null)
{
facesContext.setViewRoot(viewRoot);
defaultView = facesContext.getViewRoot().getViewId();
- }
- else
+ } else
{
facesContext.setViewRoot(new PortletUIViewRoot());
facesContext.getViewRoot().setViewId(view);
-
facesContext.getViewRoot().setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
-
portletRequest.getPortletSession().setAttribute(createViewRootKey(facesContext,
view, viewId), facesContext.getViewRoot() );
- }
- portletRequest.setAttribute(REQUEST_SERVLET_PATH,
defaultView.replaceAll("[.]jsp", ".jsf"));
- }
- else if (portletRequest instanceof RenderRequest)
+ facesContext.getViewRoot().setRenderKitId(
+ RenderKitFactory.HTML_BASIC_RENDER_KIT);
+ portletRequest.getPortletSession().setAttribute(
+ createViewRootKey(facesContext, view, viewId),
+ facesContext.getViewRoot());
+ }
+ portletRequest.setAttribute(REQUEST_SERVLET_PATH, defaultView
+ .replaceAll("[.]jsp", ".jsf"));
+ } else if (portletRequest instanceof RenderRequest)
{
// String view = portletRequest.getParameter(viewId);
- String view =
(String)portletRequest.getPortletSession().getAttribute(viewId,
PortletSession.PORTLET_SCOPE);
-
+ String view = (String) portletRequest.getPortletSession()
+ .getAttribute(viewId, PortletSession.PORTLET_SCOPE);
+
if (null == facesContext.getViewRoot())
- {
+ {
if (view == null)
{
view = defaultView;
}
- UIViewRoot viewRoot = (UIViewRoot)portletRequest.
- getPortletSession().
-
getAttribute(createViewRootKey(facesContext, view, viewId));
+ UIViewRoot viewRoot = (UIViewRoot) portletRequest
+ .getPortletSession().getAttribute(
+ createViewRootKey(facesContext, view, viewId));
if (null != viewRoot)
{
facesContext.setViewRoot(viewRoot);
defaultView = facesContext.getViewRoot().getViewId();
- }
- else
+ } else
{
facesContext.setViewRoot(new PortletUIViewRoot());
facesContext.getViewRoot().setViewId(view);
-
facesContext.getViewRoot().setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
-
portletRequest.getPortletSession().setAttribute(createViewRootKey(facesContext,
view, viewId), facesContext.getViewRoot() );
- }
+ facesContext.getViewRoot().setRenderKitId(
+ RenderKitFactory.HTML_BASIC_RENDER_KIT);
+ portletRequest.getPortletSession().setAttribute(
+ createViewRootKey(facesContext, view, viewId),
+ facesContext.getViewRoot());
+ }
}
- portletRequest.setAttribute(REQUEST_SERVLET_PATH,
view.replaceAll(".jsp", ".jsf"));
+ portletRequest.setAttribute(REQUEST_SERVLET_PATH, view.replaceAll(
+ ".jsp", ".jsf"));
+ }
+ }
+
+ /**
+ * Save FacesMessage objects on the PortletSession
+ *
+ * @param context
+ * @param session
+ */
+ private void saveFacesMessages(FacesContext context, PortletSession
session)
+ {
+ Iterator msgs = context.getMessages();
+ if (msgs != null && msgs.hasNext())
+ {
+ Map facesMsgs = new HashMap();
+
+ // messages that have a clientId
+ Iterator idsWithMsgs = context.getClientIdsWithMessages();
+ while (idsWithMsgs.hasNext())
+ {
+ String clientId = (String) idsWithMsgs.next();
+ List clientMsgList = (List) facesMsgs.get(clientId);
+ if (clientMsgList == null)
+ {
+ clientMsgList = new ArrayList();
+ facesMsgs.put(clientId, clientMsgList);
+ }
+
+ Iterator clientMsgs = context.getMessages(clientId);
+ while (clientMsgs != null && clientMsgs.hasNext())
+ {
+ clientMsgList.add(clientMsgs.next());
+ }
+ }
+
+ // messages that do not have a clientId
+ Iterator msgsWithoutId = context.getMessages(null);
+ if (msgsWithoutId != null && msgsWithoutId.hasNext())
+ {
+ List msgWithoutIdList = new ArrayList();
+ while (msgsWithoutId.hasNext())
+ {
+ msgWithoutIdList.add(msgsWithoutId.next());
+ }
+
+ facesMsgs.put("null", msgWithoutIdList);
+ }
+
+ // save messages on session
+ session.setAttribute(FACES_MESSAGES, facesMsgs);
+ }
+ }
+
+ /**
+ * Restore FacesMessage objects from the PortletSession
+ *
+ * @param context
+ * @param session
+ */
+ private void restoreFacesMessages(FacesContext context,
+ PortletSession session)
+ {
+ Map facesMsgs = (Map) session.getAttribute(FACES_MESSAGES);
+
+ if (facesMsgs != null)
+ {
+ for (Iterator clientIds = facesMsgs.keySet().iterator(); clientIds
+ .hasNext();)
+ {
+ String clientId = (String) clientIds.next();
+ List clientMsgList = (List) facesMsgs.get(clientId);
+
+ // did not originally have a clientId specified
+ if (clientId.equals("null"))
+ {
+ clientId = null;
+ }
+
+ // restore messages on the FacesContext
+ for (int index = 0; index < clientMsgList.size(); ++index)
+ {
+ FacesMessage msg = (FacesMessage) clientMsgList.get(index);
+ context.addMessage(clientId, msg);
+ }
+
+ clientMsgList.clear();
+ }
+
+ facesMsgs.clear();
+ session.setAttribute(FACES_MESSAGES, null);
+ }
+ }
+
+ /**
+ * Removes temporary JSF attributes from the request.
+ *
+ * Under certain circumstances, internal JSF attributes from one portlet
become
+ * available to another portlet on the same page (this can happen, for
example,
+ * when first portlet throws an exception while rendering). If this
happens,
+ * a portlet would not render correctly.
+ *
+ * Theoretically, Portlet server should make sure that no request
attributes
+ * from one portlet are visible to another portlet. In practice this isn't
+ * always the case, so a portlet needs to remove those request attributes
+ * before doing anything else.
+ *
+ * @param request portlet request we are processing
+ * @param response portlet response we are processing
+ */
+ protected void cleanUpAfterPortal(PortletRequest request,
+ PortletResponse response)
+ {
+ if (request != null)
+ {
+ request.removeAttribute("javax.faces.webapp.COMPONENT_TAG_STACK");
+ request.removeAttribute("javax.faces.webapp.CURRENT_VIEW_ROOT");
+
request.removeAttribute("javax.faces.webapp.CURRENT_FACES_CONTEXT");
}
-
}
-}
\ No newline at end of file
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]