|
From: Chad B. <cwb...@us...> - 2008-07-03 21:42:06
|
User: cwbrandon
Date: 08/07/03 14:42:16
Modified: andromda-jsf2/src/main/resources/templates/jsf2/flow/portlet
PortletPhaseListener.java.vsl
Log:
keep track of what views have been populated so we don't do it more than once
Revision Changes Path
1.16 +43 -5 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.15
retrieving revision 1.16
diff -u -w -r1.15 -r1.16
--- PortletPhaseListener.java.vsl 3 Jul 2008 18:27:18 -0000 1.15
+++ PortletPhaseListener.java.vsl 3 Jul 2008 21:42:15 -0000 1.16
@@ -81,7 +81,7 @@
}
}
- private String getViewId(javax.faces.event.PhaseEvent event)
+ protected String getViewId(javax.faces.event.PhaseEvent event)
{
String viewId = null;
if (event.getFacesContext() != null)
@@ -94,6 +94,9 @@
private void populateView(javax.faces.event.PhaseEvent event, String viewId)
{
+ final java.lang.Object session = event.getFacesContext().getExternalContext().getSession(false);
+ if (!this.isViewPopulated(session, viewId))
+ {
#foreach ($view in $useCases.iterator().next().allViews)
#if ($view.populatorRequired)
#set ($ifClause = "if")
@@ -106,6 +109,8 @@
}
#end
#end
+ this.setCurrentView(session, viewId);
+ }
}
@Override
@@ -116,5 +121,38 @@
{
this.populateView(event, viewId);
}
+ else
+ {
+ // - remove the current view
+ this.setCurrentView(event.getFacesContext().getExternalContext().getSession(false), null);
+ }
+ }
+
+ /**
+ * The name of the attribute that stores the current view id for this phase listener.
+ */
+ private static final String CURRENT_VIEW_ATTRIBUTE = PortletPhaseListener.class.getName() + "ViewId";
+
+ /**
+ * Keeps track of whether or not the view has already been populated (so that we don't try again).
+ *
+ * @param session the session object that stores the view id to keep track of whether or not its been populated.
+ * @param viewId the view Id.
+ * @return true if populated, false otherwise.
+ */
+ protected boolean isViewPopulated(final Object session, final String viewId)
+ {
+ final Object currentView = ${managedBeansPackage}.JsfUtils.getAttribute(session, CURRENT_VIEW_ATTRIBUTE);
+ return currentView != null && currentView.equals(viewId);
+ }
+
+ /**
+ * Sets the given viewId as the current view tracked by this portlet.
+ * @param session the session object that stores the view id to keep track of whether or not its been populated.
+ * @param viewId the view id to set.
+ */
+ protected void setCurrentView(final Object session, final String viewId)
+ {
+ ${managedBeansPackage}.JsfUtils.setAttribute(session, CURRENT_VIEW_ATTRIBUTE, viewId);
}
}
|