Author: dan.j.allen
Date: 2009-05-27 00:20:51 -0400 (Wed, 27 May 2009)
New Revision: 11010
Added:
modules/trunk/faces/src/main/java/org/jboss/seam/faces/lifecycle/ConvertStatusMessagesListener.java
modules/trunk/faces/src/main/java/org/jboss/seam/faces/lifecycle/ExecuteViewActionsListener.java
Removed:
modules/trunk/faces/src/main/java/org/jboss/seam/faces/lifecycle/TransferStatusMessagesListener.java
modules/trunk/faces/src/main/java/org/jboss/seam/faces/lifecycle/ViewActionExecutor.java
Log:
rename
Copied:
modules/trunk/faces/src/main/java/org/jboss/seam/faces/lifecycle/ConvertStatusMessagesListener.java
(from rev 10994,
modules/trunk/faces/src/main/java/org/jboss/seam/faces/lifecycle/TransferStatusMessagesListener.java)
===================================================================
---
modules/trunk/faces/src/main/java/org/jboss/seam/faces/lifecycle/ConvertStatusMessagesListener.java
(rev 0)
+++
modules/trunk/faces/src/main/java/org/jboss/seam/faces/lifecycle/ConvertStatusMessagesListener.java 2009-05-27
04:20:51 UTC (rev 11010)
@@ -0,0 +1,57 @@
+package org.jboss.seam.faces.lifecycle;
+
+import javax.enterprise.inject.AnnotationLiteral;
+import javax.enterprise.inject.UnsatisfiedResolutionException;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.faces.component.UIViewRoot;
+import javax.faces.event.SystemEvent;
+import javax.faces.event.SystemEventListener;
+
+import org.jboss.seam.bridge.ManagerBridge;
+import org.jboss.seam.faces.Faces;
+import org.jboss.seam.international.StatusMessages;
+import org.jboss.webbeans.log.LogProvider;
+import org.jboss.webbeans.log.Logging;
+
+/**
+ * <p>A {@link SystemEventListener} that observes the PreRenderViewEvent or
+ * a redirect navigation event (via SeamViewHandler) and transposes Seam
+ * StatusMessage objects into FacesMessage objects and transfers them to the
FacesContext.</p>
+ *
+ * <p>FIXME the messages are going to get dropped if a view action causes a
navigation event followed by a redirect event</p>
+ *
+ * @author Dan Allen
+ */
+//@ListenerFor(systemEventClass = PreRenderViewEvent.class, sourceClass =
UIViewRoot.class)
+public class ConvertStatusMessagesListener implements SystemEventListener
+{
+ private static final LogProvider log =
Logging.getLogProvider(ConvertStatusMessagesListener.class);
+
+ public boolean isListenerForSource(Object source)
+ {
+ return source instanceof UIViewRoot;
+ }
+
+ public void processEvent(SystemEvent preRenderViewEvent)
+ {
+ execute();
+ }
+
+ public void execute()
+ {
+ try
+ {
+ BeanManager manager = ManagerBridge.getProvider().getCurrentManager();
+ // tests
+ if (manager != null)
+ {
+ manager.getInstanceByType(StatusMessages.class, new
AnnotationLiteral<Faces>() {}).onBeforeRender();
+ }
+ }
+ catch (UnsatisfiedResolutionException e)
+ {
+ log.warn("Could not locate the StatusMessages bean. Status messages will
not be transfered to the FacesContext.");
+ }
+
+ }
+}
Copied:
modules/trunk/faces/src/main/java/org/jboss/seam/faces/lifecycle/ExecuteViewActionsListener.java
(from rev 10994,
modules/trunk/faces/src/main/java/org/jboss/seam/faces/lifecycle/ViewActionExecutor.java)
===================================================================
---
modules/trunk/faces/src/main/java/org/jboss/seam/faces/lifecycle/ExecuteViewActionsListener.java
(rev 0)
+++
modules/trunk/faces/src/main/java/org/jboss/seam/faces/lifecycle/ExecuteViewActionsListener.java 2009-05-27
04:20:51 UTC (rev 11010)
@@ -0,0 +1,228 @@
+package org.jboss.seam.faces.lifecycle;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+
+import javax.el.ELException;
+import javax.el.MethodExpression;
+import javax.faces.FacesException;
+import javax.faces.application.NavigationHandler;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIViewRoot;
+import javax.faces.context.FacesContext;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.ExceptionQueuedEvent;
+import javax.faces.event.ExceptionQueuedEventContext;
+import javax.faces.event.SystemEvent;
+import javax.faces.event.SystemEventListener;
+
+import org.jboss.seam.bridge.ManagerBridge;
+import org.jboss.seam.faces.component.UIRestrictView;
+import org.jboss.seam.faces.component.UIViewAction;
+import org.jboss.seam.security.Identity;
+import org.jboss.webbeans.log.Log;
+import org.jboss.webbeans.log.Logging;
+
+//@ListenerFor(systemEventClass = PreRenderViewEvent.class, sourceClass =
UIViewRoot.class)
+public class ExecuteViewActionsListener implements SystemEventListener
+{
+ private static final Log log = Logging.getLog(ExecuteViewActionsListener.class);
+
+ public boolean isListenerForSource(Object source)
+ {
+ return source instanceof UIViewRoot;
+ }
+
+ public void processEvent(SystemEvent event) throws AbortProcessingException
+ {
+ execute();
+ }
+
+ protected void execute()
+ {
+ FacesContext context = FacesContext.getCurrentInstance();
+ UIViewRoot initialViewRoot = context.getViewRoot();
+
+ // TEMPORARY needs to be organized better
+
+ // collect first so as not to introduce a hard dependency on Identity if tag is not
in use
+ Collection<UIRestrictView> restrictions =
collectionViewRestrictions(initialViewRoot);
+ if (!restrictions.isEmpty())
+ {
+ if (Identity.isSecurityEnabled())
+ {
+ if (log.isTraceEnabled())
+ {
+ log.trace("Processing view restrictions before render view");
+ }
+
+ Identity identity =
ManagerBridge.getProvider().getCurrentManager().getInstanceByType(Identity.class);
+ try
+ {
+ for (UIRestrictView restriction : restrictions)
+ {
+ if (restriction.getRequire() != null)
+ {
+ identity.checkRestriction(restriction.getRequire());
+ }
+ else
+ {
+ identity.checkPermission(initialViewRoot.getViewId(),
"render");
+ }
+ }
+ }
+ // FIXME damn this is ugly, but JCDI is wrapping exceptions
+ catch (Exception e)
+ {
+ Throwable cause = e;
+ if (e instanceof InvocationTargetException)
+ {
+ cause = e.getCause();
+ }
+
+ context.getApplication().publishEvent(context, ExceptionQueuedEvent.class,
new ExceptionQueuedEventContext(context, cause));
+ // FIXME this is lame; there should be some other way to stop view
rendering
+ context.getViewRoot().setRendered(false);
+ throw new AbortProcessingException("View restriction criteria was not
met.");
+ //return;
+ }
+ }
+ }
+ // END TEMPORARY
+
+ if (log.isTraceEnabled())
+ {
+ log.trace("Processing view actions before render view");
+ }
+
+ NavigationHandler navHandler = context.getApplication().getNavigationHandler();
+ boolean postback = context.isPostback();
+
+ if (!postback && context.isValidationFailed())
+ {
+ if (log.isTraceEnabled())
+ {
+ log.trace("Validation flagged as failed. Calling navigation handler
without executing view actions.");
+ }
+ navHandler.handleNavigation(context, null, null);
+ return;
+ }
+
+ Collection<UIViewAction> actions = collectViewActions(initialViewRoot,
postback);
+ for (UIViewAction action : actions)
+ {
+ String outcome = null;
+ String fromAction = null;
+
+ MethodExpression execute = action.getExecute();
+ // QUESTION shouldn't this be an illegal state otherwise??
+ if (execute != null)
+ {
+ if (log.isDebugEnabled())
+ {
+ log.debug("Executing view action expression {0}",
execute.getExpressionString());
+ }
+ try
+ {
+ Object returnVal = execute.invoke(context.getELContext(), null);
+ outcome = (returnVal != null ? returnVal.toString() : null);
+ fromAction = execute.getExpressionString();
+ }
+ catch (ELException e)
+ {
+ if (log.isErrorEnabled())
+ {
+ log.error(e.getMessage(), e);
+ }
+ throw new FacesException(execute.getExpressionString() + ": " +
e.getMessage(), e);
+ }
+ }
+
+ navHandler.handleNavigation(context, fromAction, outcome);
+
+ // QUESTION In either of these two cases, should an AbortProcessingEvent
exception be thrown?
+ if (context.getResponseComplete())
+ {
+ if (log.isDebugEnabled())
+ {
+ log.debug("Response marked as complete during view action processing.
Short-circuiting remaining actions.");
+ }
+ // FIXME this is lame; there should be some other way to stop view rendering
+ context.getViewRoot().setRendered(false);
+ break;
+ }
+ else if
(!initialViewRoot.getViewId().equals(context.getViewRoot().getViewId()))
+ {
+ if (log.isDebugEnabled())
+ {
+ log.debug("Detected change in view ID during view action processing.
Short-circuiting remaining actions.");
+ }
+ break;
+ }
+ }
+ }
+
+ /**
+ * Pick out the UIRestrictView components from the metadata facet's children. If
no
+ * matches are found, an unmodifiable empty list is returned.
+ */
+ protected Collection<UIRestrictView> collectionViewRestrictions(UIViewRoot
viewRoot)
+ {
+ return collectMetadataComponents(viewRoot, new
UIComponentFilter<UIRestrictView>() {
+
+ @Override
+ public boolean accepts(UIComponent candidate)
+ {
+ return candidate instanceof UIRestrictView;
+ }
+
+ });
+ }
+
+ /**
+ * Pick out the UIViewAction components from the metadata facet's children. If
this is a postback,
+ * only select UIViewAction components that are to be executed on a postback. If no
matches
+ * are found, an unmodifiable empty list is returned.
+ */
+ protected Collection<UIViewAction> collectViewActions(UIViewRoot viewRoot, final
boolean postback)
+ {
+ return collectMetadataComponents(viewRoot, new
UIComponentFilter<UIViewAction>() {
+
+ @Override
+ public boolean accepts(UIComponent candidate)
+ {
+ return candidate instanceof UIViewAction && (!postback ||
((UIViewAction) candidate).isOnPostback());
+ }
+
+ });
+ }
+
+ protected <C extends UIComponent> Collection<C>
collectMetadataComponents(UIViewRoot viewRoot, UIComponentFilter<C>
componentFilter)
+ {
+ UIComponent metadataFacet = viewRoot.getFacet(UIViewRoot.METADATA_FACET_NAME);
+
+ if (metadataFacet == null)
+ {
+ return Collections.<C>emptyList();
+ }
+
+ Collection<C> matches = new ArrayList<C>();
+ for (UIComponent candidate : metadataFacet.getChildren())
+ {
+ if (componentFilter.accepts(candidate))
+ {
+ matches.add((C) candidate);
+ }
+ }
+
+ return matches;
+ }
+
+ protected abstract class UIComponentFilter<C extends UIComponent>
+ {
+ public abstract boolean accepts(UIComponent candidate);
+ }
+
+}
Deleted:
modules/trunk/faces/src/main/java/org/jboss/seam/faces/lifecycle/TransferStatusMessagesListener.java
===================================================================
---
modules/trunk/faces/src/main/java/org/jboss/seam/faces/lifecycle/TransferStatusMessagesListener.java 2009-05-26
23:01:28 UTC (rev 11009)
+++
modules/trunk/faces/src/main/java/org/jboss/seam/faces/lifecycle/TransferStatusMessagesListener.java 2009-05-27
04:20:51 UTC (rev 11010)
@@ -1,55 +0,0 @@
-package org.jboss.seam.faces.lifecycle;
-
-import javax.enterprise.inject.UnsatisfiedResolutionException;
-import javax.enterprise.inject.spi.BeanManager;
-import javax.faces.component.UIViewRoot;
-import javax.faces.event.SystemEvent;
-import javax.faces.event.SystemEventListener;
-
-import org.jboss.seam.bridge.ManagerBridge;
-import org.jboss.seam.international.StatusMessages;
-import org.jboss.webbeans.log.LogProvider;
-import org.jboss.webbeans.log.Logging;
-
-/**
- * A {@link SystemEventListener} that observes the PreRenderViewEvent or
- * a redirect navigation event (via SeamViewHandler) and transposes Seam
- * StatusMessage objects into FacesMessage objects and transfers them to the
FacesContext.
- *
- * FIXME this is going to be a problem if a view action causes a navigation event
followed by a redirect event
- *
- * @author Dan Allen
- */
-//@ListenerFor(systemEventClass = PreRenderViewEvent.class, sourceClass =
UIViewRoot.class)
-public class TransferStatusMessagesListener implements SystemEventListener
-{
- private static final LogProvider log =
Logging.getLogProvider(TransferStatusMessagesListener.class);
-
- public boolean isListenerForSource(Object source)
- {
- return source instanceof UIViewRoot;
- }
-
- public void processEvent(SystemEvent preRenderViewEvent)
- {
- execute();
- }
-
- public void execute()
- {
- try
- {
- BeanManager manager = ManagerBridge.getProvider().getCurrentManager();
- // tests
- if (manager != null)
- {
- manager.getInstanceByType(StatusMessages.class).onBeforeRender();
- }
- }
- catch (UnsatisfiedResolutionException e)
- {
- log.warn("Could not locate the StatusMessages bean. Status messages will
not be transfered to the FacesContext.");
- }
-
- }
-}
Deleted:
modules/trunk/faces/src/main/java/org/jboss/seam/faces/lifecycle/ViewActionExecutor.java
===================================================================
---
modules/trunk/faces/src/main/java/org/jboss/seam/faces/lifecycle/ViewActionExecutor.java 2009-05-26
23:01:28 UTC (rev 11009)
+++
modules/trunk/faces/src/main/java/org/jboss/seam/faces/lifecycle/ViewActionExecutor.java 2009-05-27
04:20:51 UTC (rev 11010)
@@ -1,228 +0,0 @@
-package org.jboss.seam.faces.lifecycle;
-
-import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-
-import javax.el.ELException;
-import javax.el.MethodExpression;
-import javax.faces.FacesException;
-import javax.faces.application.NavigationHandler;
-import javax.faces.component.UIComponent;
-import javax.faces.component.UIViewRoot;
-import javax.faces.context.FacesContext;
-import javax.faces.event.AbortProcessingException;
-import javax.faces.event.ExceptionQueuedEvent;
-import javax.faces.event.ExceptionQueuedEventContext;
-import javax.faces.event.SystemEvent;
-import javax.faces.event.SystemEventListener;
-
-import org.jboss.seam.bridge.ManagerBridge;
-import org.jboss.seam.faces.component.UIRestrictView;
-import org.jboss.seam.faces.component.UIViewAction;
-import org.jboss.seam.security.Identity;
-import org.jboss.webbeans.log.Log;
-import org.jboss.webbeans.log.Logging;
-
-//@ListenerFor(systemEventClass = PreRenderViewEvent.class, sourceClass =
UIViewRoot.class)
-public class ViewActionExecutor implements SystemEventListener
-{
- private static final Log log = Logging.getLog(ViewActionExecutor.class);
-
- public boolean isListenerForSource(Object source)
- {
- return source instanceof UIViewRoot;
- }
-
- public void processEvent(SystemEvent event) throws AbortProcessingException
- {
- processViewActions();
- }
-
- protected void processViewActions()
- {
- FacesContext context = FacesContext.getCurrentInstance();
- UIViewRoot initialViewRoot = context.getViewRoot();
-
- // TEMPORARY needs to be organized better
-
- // collect first so as not to introduce a hard dependency on Identity if tag is not
in use
- Collection<UIRestrictView> restrictions =
collectionViewRestrictions(initialViewRoot);
- if (!restrictions.isEmpty())
- {
- if (Identity.isSecurityEnabled())
- {
- if (log.isTraceEnabled())
- {
- log.trace("Processing view restrictions before render view");
- }
-
- Identity identity =
ManagerBridge.getProvider().getCurrentManager().getInstanceByType(Identity.class);
- try
- {
- for (UIRestrictView restriction : restrictions)
- {
- if (restriction.getRequire() != null)
- {
- identity.checkRestriction(restriction.getRequire());
- }
- else
- {
- identity.checkPermission(initialViewRoot.getViewId(),
"render");
- }
- }
- }
- // FIXME damn this is ugly, but JCDI is wrapping exceptions
- catch (Exception e)
- {
- Throwable cause = e;
- if (e instanceof InvocationTargetException)
- {
- cause = e.getCause();
- }
-
- context.getApplication().publishEvent(context, ExceptionQueuedEvent.class,
new ExceptionQueuedEventContext(context, cause));
- // FIXME this is lame; there should be some other way to stop view
rendering
- context.getViewRoot().setRendered(false);
- throw new AbortProcessingException("View restriction criteria was not
met.");
- //return;
- }
- }
- }
- // END TEMPORARY
-
- if (log.isTraceEnabled())
- {
- log.trace("Processing view actions before render view");
- }
-
- NavigationHandler navHandler = context.getApplication().getNavigationHandler();
- boolean postback = context.isPostback();
-
- if (!postback && context.isValidationFailed())
- {
- if (log.isTraceEnabled())
- {
- log.trace("Validation flagged as failed. Calling navigation handler
without executing view actions.");
- }
- navHandler.handleNavigation(context, null, null);
- return;
- }
-
- Collection<UIViewAction> actions = collectViewActions(initialViewRoot,
postback);
- for (UIViewAction action : actions)
- {
- String outcome = null;
- String fromAction = null;
-
- MethodExpression execute = action.getExecute();
- // QUESTION shouldn't this be an illegal state otherwise??
- if (execute != null)
- {
- if (log.isDebugEnabled())
- {
- log.debug("Executing view action expression {0}",
execute.getExpressionString());
- }
- try
- {
- Object returnVal = execute.invoke(context.getELContext(), null);
- outcome = (returnVal != null ? returnVal.toString() : null);
- fromAction = execute.getExpressionString();
- }
- catch (ELException e)
- {
- if (log.isErrorEnabled())
- {
- log.error(e.getMessage(), e);
- }
- throw new FacesException(execute.getExpressionString() + ": " +
e.getMessage(), e);
- }
- }
-
- navHandler.handleNavigation(context, fromAction, outcome);
-
- // QUESTION In either of these two cases, should an AbortProcessingEvent
exception be thrown?
- if (context.getResponseComplete())
- {
- if (log.isDebugEnabled())
- {
- log.debug("Response marked as complete during view action processing.
Short-circuiting remaining actions.");
- }
- // FIXME this is lame; there should be some other way to stop view rendering
- context.getViewRoot().setRendered(false);
- break;
- }
- else if
(!initialViewRoot.getViewId().equals(context.getViewRoot().getViewId()))
- {
- if (log.isDebugEnabled())
- {
- log.debug("Detected change in view ID during view action processing.
Short-circuiting remaining actions.");
- }
- break;
- }
- }
- }
-
- /**
- * Pick out the UIRestrictView components from the metadata facet's children. If
no
- * matches are found, an unmodifiable empty list is returned.
- */
- protected Collection<UIRestrictView> collectionViewRestrictions(UIViewRoot
viewRoot)
- {
- return collectMetadataComponents(viewRoot, new
UIComponentFilter<UIRestrictView>() {
-
- @Override
- public boolean accept(UIComponent candidate)
- {
- return candidate instanceof UIRestrictView;
- }
-
- });
- }
-
- /**
- * Pick out the UIViewAction components from the metadata facet's children. If
this is a postback,
- * only select UIViewAction components that are to be executed on a postback. If no
matches
- * are found, an unmodifiable empty list is returned.
- */
- protected Collection<UIViewAction> collectViewActions(UIViewRoot viewRoot, final
boolean postback)
- {
- return collectMetadataComponents(viewRoot, new
UIComponentFilter<UIViewAction>() {
-
- @Override
- public boolean accept(UIComponent candidate)
- {
- return candidate instanceof UIViewAction && (!postback ||
((UIViewAction) candidate).isOnPostback());
- }
-
- });
- }
-
- protected <C extends UIComponent> Collection<C>
collectMetadataComponents(UIViewRoot viewRoot, UIComponentFilter<C>
componentFilter)
- {
- UIComponent metadataFacet = viewRoot.getFacet(UIViewRoot.METADATA_FACET_NAME);
-
- if (metadataFacet == null)
- {
- return Collections.<C>emptyList();
- }
-
- Collection<C> matches = new ArrayList<C>();
- for (UIComponent candidate : metadataFacet.getChildren())
- {
- if (componentFilter.accept(candidate))
- {
- matches.add((C) candidate);
- }
- }
-
- return matches;
- }
-
- protected abstract class UIComponentFilter<C extends UIComponent>
- {
- public abstract boolean accept(UIComponent candidate);
- }
-
-}