myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bom...@apache.org
Subject svn commit: r707969 - in /myfaces/trinidad/trunk_1.2.x/trinidad-partial-lifecycle/src/main: java/org/apache/myfaces/trinidadinternal/lifecycle/ resources/META-INF/
Date Sun, 26 Oct 2008 11:41:04 GMT
Author: bommel
Date: Sun Oct 26 04:41:03 2008
New Revision: 707969

URL: http://svn.apache.org/viewvc?rev=707969&view=rev
Log:
(TRINIDAD-1220) Partial Lifecycle for Trinidad

Added:
    myfaces/trinidad/trunk_1.2.x/trinidad-partial-lifecycle/src/main/java/org/apache/myfaces/trinidadinternal/lifecycle/UIViewRoot.java
  (with props)
    myfaces/trinidad/trunk_1.2.x/trinidad-partial-lifecycle/src/main/resources/META-INF/faces-config.xml
  (with props)
Modified:
    myfaces/trinidad/trunk_1.2.x/trinidad-partial-lifecycle/src/main/java/org/apache/myfaces/trinidadinternal/lifecycle/ApplyRequestValuesExecutor.java
    myfaces/trinidad/trunk_1.2.x/trinidad-partial-lifecycle/src/main/java/org/apache/myfaces/trinidadinternal/lifecycle/ProcessValidationsExecutor.java
    myfaces/trinidad/trunk_1.2.x/trinidad-partial-lifecycle/src/main/java/org/apache/myfaces/trinidadinternal/lifecycle/RenderResponseExecutor.java
    myfaces/trinidad/trunk_1.2.x/trinidad-partial-lifecycle/src/main/java/org/apache/myfaces/trinidadinternal/lifecycle/UpdateModelValuesExecutor.java

Modified: myfaces/trinidad/trunk_1.2.x/trinidad-partial-lifecycle/src/main/java/org/apache/myfaces/trinidadinternal/lifecycle/ApplyRequestValuesExecutor.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk_1.2.x/trinidad-partial-lifecycle/src/main/java/org/apache/myfaces/trinidadinternal/lifecycle/ApplyRequestValuesExecutor.java?rev=707969&r1=707968&r2=707969&view=diff
==============================================================================
--- myfaces/trinidad/trunk_1.2.x/trinidad-partial-lifecycle/src/main/java/org/apache/myfaces/trinidadinternal/lifecycle/ApplyRequestValuesExecutor.java
(original)
+++ myfaces/trinidad/trunk_1.2.x/trinidad-partial-lifecycle/src/main/java/org/apache/myfaces/trinidadinternal/lifecycle/ApplyRequestValuesExecutor.java
Sun Oct 26 04:41:03 2008
@@ -24,7 +24,6 @@
 
 import javax.faces.component.ContextCallback;
 import javax.faces.component.UIComponent;
-import javax.faces.component.UIViewRoot;
 import javax.faces.context.FacesContext;
 import javax.faces.event.PhaseId;
 import java.util.ArrayList;
@@ -48,45 +47,53 @@
   {
 
     String[] partialTargets = PartialLifecycleUtils.getPartialTargets(facesContext);
-    if (partialTargets != null)
+    if (!(facesContext.getViewRoot() instanceof UIViewRoot)) {
+      LOG.severe("ViewRoot is not instanceof " + UIViewRoot.class.getName() + " skipping
partial lifecycle");
+    }
+    if (partialTargets != null && facesContext.getViewRoot() instanceof UIViewRoot)
     {
       Map<String, String> parameterMap = facesContext.getExternalContext().getRequestParameterMap();
-      UIViewRoot viewRoot = facesContext.getViewRoot();
-      // TODO partialRequest from inside Tree or Table
-
-      // TODO navigationTree
+      UIViewRoot viewRoot = (UIViewRoot) facesContext.getViewRoot();
 
-      for (String partialTarget : partialTargets)
+      if (!viewRoot.notifyListeners(facesContext, PhaseId.APPLY_REQUEST_VALUES,
+          viewRoot.getBeforePhaseListener(), true))
       {
-        viewRoot.invokeOnComponent(facesContext, partialTarget, processDecodesCallback);
-      }
+        // TODO partialRequest from inside Tree or Table
 
-      // TODO how to check that source and form already included in a partialTarget
-      String sourceName = parameterMap.get("source");
-      if (sourceName != null && !Arrays.asList(partialTargets).contains(sourceName))
-      {
-        // TODO source inside a partialTarget
-        boolean found = viewRoot.invokeOnComponent(facesContext, sourceName, decodeCallback);
-        if (!found)
+        // TODO navigationTree
+
+        for (String partialTarget : partialTargets)
         {
-          LOG.warning("No source UIComponent found for '" + sourceName + "'");
+          viewRoot.invokeOnComponent(facesContext, partialTarget, processDecodesCallback);
         }
-      }
 
-      String formName = parameterMap.get(CoreResponseStateManager.FORM_FIELD_NAME);
-      if (formName != null && !Arrays.asList(partialTargets).contains(formName))
-      {
-        // TODO form inside partialTarget
-        // SubForm set submitted by queueEvent
-        boolean found = viewRoot.invokeOnComponent(facesContext, formName, decodeCallback);
-        if (!found)
+        // TODO how to check that source and form already included in a partialTarget
+        String sourceName = parameterMap.get("source");
+        if (sourceName != null && !Arrays.asList(partialTargets).contains(sourceName))
         {
-          LOG.warning("No form UIComponent found for '" + formName + "'");
+          // TODO source inside a partialTarget
+          boolean found = viewRoot.invokeOnComponent(facesContext, sourceName, decodeCallback);
+          if (!found)
+          {
+            LOG.warning("No source UIComponent found for '" + sourceName + "'");
+          }
         }
-      }
 
-      // TODO broadcast Events UIViewRoot has no public method
-      //viewRoot.broadcastEventsForPhase(facesContext, PhaseId.APPLY_REQUEST_VALUES);
+        String formName = parameterMap.get(CoreResponseStateManager.FORM_FIELD_NAME);
+        if (formName != null && !Arrays.asList(partialTargets).contains(formName))
+        {
+          // TODO form inside partialTarget
+          // SubForm set submitted by queueEvent
+          boolean found = viewRoot.invokeOnComponent(facesContext, formName, decodeCallback);
+          if (!found)
+          {
+            LOG.warning("No form UIComponent found for '" + formName + "'");
+          }
+        }
+        viewRoot.broadcastForPhase(PhaseId.APPLY_REQUEST_VALUES);
+      }
+      viewRoot.clearEvents(facesContext);
+      viewRoot.notifyListeners(facesContext, PhaseId.APPLY_REQUEST_VALUES, viewRoot.getBeforePhaseListener(),
false);
 
     } else
     {
@@ -96,9 +103,8 @@
       if (!(facesContext.getResponseComplete() || facesContext.getRenderResponse())
           && requestContext.isPartialRequest(facesContext))
       {
-        UIViewRoot viewRoot = facesContext.getViewRoot();
-        UIComponent source =
-            viewRoot.findComponent(facesContext.getExternalContext().getRequestParameterMap().get("source"));
+        UIComponent source = facesContext.getViewRoot()
+            .findComponent(facesContext.getExternalContext().getRequestParameterMap().get("source"));
         if (source != null)
         {
           List<String> list = new ArrayList<String>();

Modified: myfaces/trinidad/trunk_1.2.x/trinidad-partial-lifecycle/src/main/java/org/apache/myfaces/trinidadinternal/lifecycle/ProcessValidationsExecutor.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk_1.2.x/trinidad-partial-lifecycle/src/main/java/org/apache/myfaces/trinidadinternal/lifecycle/ProcessValidationsExecutor.java?rev=707969&r1=707968&r2=707969&view=diff
==============================================================================
--- myfaces/trinidad/trunk_1.2.x/trinidad-partial-lifecycle/src/main/java/org/apache/myfaces/trinidadinternal/lifecycle/ProcessValidationsExecutor.java
(original)
+++ myfaces/trinidad/trunk_1.2.x/trinidad-partial-lifecycle/src/main/java/org/apache/myfaces/trinidadinternal/lifecycle/ProcessValidationsExecutor.java
Sun Oct 26 04:41:03 2008
@@ -29,15 +29,20 @@
   public boolean execute(FacesContext facesContext)
   {
     String[] partialTargets = PartialLifecycleUtils.getPartialTargets(facesContext);
-    if (partialTargets != null)
+    if (partialTargets != null && facesContext.getViewRoot() instanceof UIViewRoot)
     {
-      for (String clientId : partialTargets)
+      UIViewRoot viewRoot = (UIViewRoot) facesContext.getViewRoot();
+      if (!viewRoot.notifyListeners(facesContext, PhaseId.PROCESS_VALIDATIONS,
+          viewRoot.getBeforePhaseListener(), true))
       {
-        facesContext.getViewRoot().invokeOnComponent(facesContext, clientId, contextCallback);
+        for (String clientId : partialTargets)
+        {
+          facesContext.getViewRoot().invokeOnComponent(facesContext, clientId, contextCallback);
+        }
+        viewRoot.broadcastForPhase(PhaseId.PROCESS_VALIDATIONS);
       }
-      //UIViewRoot viewRoot = facesContext.getViewRoot();
-      // TODO broadcast Events UIViewRoot has no public method
-      //viewRoot.broadcastEventsForPhase(facesContext, PROCESS_VALIDATIONS);
+      viewRoot.clearEvents(facesContext);
+      viewRoot.notifyListeners(facesContext, PhaseId.PROCESS_VALIDATIONS, viewRoot.getBeforePhaseListener(),
false);
     } else
     {
       facesContext.getViewRoot().processValidators(facesContext);

Modified: myfaces/trinidad/trunk_1.2.x/trinidad-partial-lifecycle/src/main/java/org/apache/myfaces/trinidadinternal/lifecycle/RenderResponseExecutor.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk_1.2.x/trinidad-partial-lifecycle/src/main/java/org/apache/myfaces/trinidadinternal/lifecycle/RenderResponseExecutor.java?rev=707969&r1=707968&r2=707969&view=diff
==============================================================================
--- myfaces/trinidad/trunk_1.2.x/trinidad-partial-lifecycle/src/main/java/org/apache/myfaces/trinidadinternal/lifecycle/RenderResponseExecutor.java
(original)
+++ myfaces/trinidad/trunk_1.2.x/trinidad-partial-lifecycle/src/main/java/org/apache/myfaces/trinidadinternal/lifecycle/RenderResponseExecutor.java
Sun Oct 26 04:41:03 2008
@@ -22,132 +22,141 @@
 import javax.faces.FacesException;
 import javax.faces.application.Application;
 import javax.faces.application.ViewHandler;
-import javax.faces.component.ContextCallback;
 import javax.faces.context.FacesContext;
 import javax.faces.event.PhaseId;
 import java.io.IOException;
 
 public class RenderResponseExecutor implements PhaseExecutor
 {
-  private static final TrinidadLogger LOG = TrinidadLogger.createTrinidadLogger(RenderResponseExecutor.class);
-  private ContextCallback contextCallback = new RenderResponseCallback();
+  //private static final TrinidadLogger LOG = TrinidadLogger.createTrinidadLogger(RenderResponseExecutor.class);
+  //private ContextCallback contextCallback = new RenderResponseCallback();
 
   public boolean execute(FacesContext facesContext)
   {
-
     try
     {
+      /*
       // TODO partial rendering
-      /*String[] partialTargets = PartialLifecycleUtils.getPartialTargets(facesContext);
-      if (partialTargets != null)
+      String[] partialTargets = PartialLifecycleUtils.getPartialTargets(facesContext);
+      if (partialTargets != null && facesContext.getViewRoot() instanceof UIViewRoot)
       {
-        // Most of this is a copy from ViewHandlerImpl
-        // See if there is a possiblity of short-circuiting the current
-        // Render Response
-        ExtendedRenderKitService service = Service.getService(facesContext.getRenderKit(),
ExtendedRenderKitService.class);
-        if ((service != null) && service.shortCircuitRenderView(facesContext))
-        {
-          // Yup, we don't need to do anything
-          return false;
-        } else
+
+        UIViewRoot viewRoot = (UIViewRoot) facesContext.getViewRoot();
+        if (!viewRoot.notifyListeners(facesContext, PhaseId.RENDER_RESPONSE, viewRoot.getBeforePhaseListener(),
true))
         {
-          try
+          // Most of this is a copy from ViewHandlerImpl
+          // See if there is a possiblity of short-circuiting the current
+          // Render Response
+          ExtendedRenderKitService service =
+              Service.getService(facesContext.getRenderKit(), ExtendedRenderKitService.class);
+          if ((service != null) && service.shortCircuitRenderView(facesContext))
           {
-            if (service != null)
+            // Yup, we don't need to do anything
+            return false;
+          } else
+          {
+            try
             {
-              service.encodeBegin(facesContext);
-            }
-            HttpServletResponse response =
-                (HttpServletResponse) facesContext.getExternalContext().getResponse();
-            String contentType = "text/html";
-            String encoding = "UTF-8";
-
-            // TODO JspUtils.getEncoding(facesContext, "UTF-8");
-
-            response.setContentType(contentType +
-                "; charset=" + encoding);
-
-            ResponseWriter responseWriter =
-                facesContext.getRenderKit().createResponseWriter(response.getWriter(), contentType,
encoding);
-            LOG.info("ResponseWriter class: " + responseWriter.getClass().getName());
-            facesContext.setResponseWriter(responseWriter);
-
-            ResponseWriter rw = facesContext.getResponseWriter();
-
-            // TODO Messages
-            if (facesContext.getMessages().hasNext()) {
-              // add messages to partialTargets
-            }
+              if (service != null)
+              {
+                service.encodeBegin(facesContext);
+              }
+              HttpServletResponse response =
+                  (HttpServletResponse) facesContext.getExternalContext().getResponse();
+              String contentType = "text/html";
+              String encoding = "UTF-8";
 
-            RenderingContext renderingContext = RenderingContext.getCurrentInstance();
-            // ensure mark PPR active
-            if (PartialPageUtils.isPartialRenderingPass(renderingContext)) {
-              PartialPageUtils.markPPRActive(facesContext);
-            }
-            rw.startDocument();
+              // TODO JspUtils.getEncoding(facesContext, "UTF-8");
 
-            Map<String, String> parameterMap = facesContext.getExternalContext().getRequestParameterMap();
-            String formName = parameterMap.get(CoreResponseStateManager.FORM_FIELD_NAME);
-            UIComponent form = facesContext.getViewRoot().findComponent(formName);
+              response.setContentType(contentType +
+                  "; charset=" + encoding);
 
-            // TODO form inside partial Target
-            if (form != null)
-            {
+              ResponseWriter responseWriter =
+                  facesContext.getRenderKit().createResponseWriter(response.getWriter(),
contentType, encoding);
+              LOG.info("ResponseWriter class: " + responseWriter.getClass().getName());
+              facesContext.setResponseWriter(responseWriter);
 
-              // TODO find a better way or should form.encodeBegin called?
-              //CoreFormData formData = new CoreFormData(formName);
-              // FIXME
-              //formData.addNeededValue(XhtmlConstants.PARTIAL_PARAM);
-              //formData.addNeededValue(XhtmlConstants.STATE_PARAM);
-              //formData.addNeededValue(XhtmlConstants.VALUE_PARAM);
-
-              //renderingContext.setFormData(formData);
-              form.encodeBegin(facesContext);
-              FormData formData = renderingContext.getFormData();
-              formData.addNeededValue(XhtmlConstants.PARTIAL_PARAM);
-              formData.addNeededValue(XhtmlConstants.STATE_PARAM);
-              formData.addNeededValue(XhtmlConstants.VALUE_PARAM);
+              ResponseWriter rw = facesContext.getResponseWriter();
 
-              // FIXME
-              if (renderingContext instanceof CoreRenderingContext)
+              // TODO Messages
+              if (facesContext.getMessages().hasNext())
               {
-                Map<String, String> shortStyles = renderingContext.getSkin().getStyleClassMap(renderingContext);
-                ((CoreRenderingContext) renderingContext).setStyleMap(shortStyles);
+                // add messages to partialTargets
               }
-            }
 
-            for (String clientId : partialTargets)
-            {
-              LOG.info("Rendering partialTarget " + clientId);
-              facesContext.getViewRoot().invokeOnComponent(facesContext, clientId, contextCallback);
-            }
+              RenderingContext renderingContext = RenderingContext.getCurrentInstance();
+              // ensure mark PPR active
+              if (PartialPageUtils.isPartialRenderingPass(renderingContext))
+              {
+                PartialPageUtils.markPPRActive(facesContext);
+              }
+              rw.startDocument();
 
-            // TODO writeState is performed by patched FormRenderer 
-            // find a better way
-            if (form != null)
-            {
-              form.encodeEnd(facesContext);
-            }
-            rw.endDocument();
+              Map<String, String> parameterMap = facesContext.getExternalContext().getRequestParameterMap();
+              String formName = parameterMap.get(CoreResponseStateManager.FORM_FIELD_NAME);
+              UIComponent form = facesContext.getViewRoot().findComponent(formName);
 
-            if (service != null)
-            {
-              service.encodeEnd(facesContext);
+              // TODO form inside partial Target
+              if (form != null)
+              {
+
+                // TODO find a better way or should form.encodeBegin called?
+                //CoreFormData formData = new CoreFormData(formName);
+                // FIXME
+                //formData.addNeededValue(XhtmlConstants.PARTIAL_PARAM);
+                //formData.addNeededValue(XhtmlConstants.STATE_PARAM);
+                //formData.addNeededValue(XhtmlConstants.VALUE_PARAM);
+
+                //renderingContext.setFormData(formData);
+                form.encodeBegin(facesContext);
+                FormData formData = renderingContext.getFormData();
+                formData.addNeededValue(XhtmlConstants.PARTIAL_PARAM);
+                formData.addNeededValue(XhtmlConstants.STATE_PARAM);
+                formData.addNeededValue(XhtmlConstants.VALUE_PARAM);
+
+                // FIXME
+                if (renderingContext instanceof CoreRenderingContext)
+                {
+                  Map<String, String> shortStyles = renderingContext.getSkin().getStyleClassMap(renderingContext);
+                  ((CoreRenderingContext) renderingContext).setStyleMap(shortStyles);
+                }
+              }
+
+              for (String clientId : partialTargets)
+              {
+                LOG.info("Rendering partialTarget " + clientId);
+                facesContext.getViewRoot().invokeOnComponent(facesContext, clientId, contextCallback);
+              }
+
+              // TODO writeState is performed by patched FormRenderer
+              // find a better way
+              if (form != null)
+              {
+                form.encodeEnd(facesContext);
+              }
+              rw.endDocument();
+
+              if (service != null)
+              {
+                service.encodeEnd(facesContext);
+              }
             }
-          }
-          finally
-          {
-            if (service != null)
+            finally
             {
-              service.encodeFinally(facesContext);
+              if (service != null)
+              {
+                service.encodeFinally(facesContext);
+              }
             }
           }
         }
-      } else
-      { */
-      Application application = facesContext.getApplication();
-      ViewHandler viewHandler = application.getViewHandler();
-      viewHandler.renderView(facesContext, facesContext.getViewRoot());
+        notifyListeners(context, PhaseId.RENDER_RESPONSE, getAfterPhaseListener(), false);
+      }
+      else
+      {*/
+        Application application = facesContext.getApplication();
+        ViewHandler viewHandler = application.getViewHandler();
+        viewHandler.renderView(facesContext, facesContext.getViewRoot());
       //}
     } catch (IOException e)
     {

Added: myfaces/trinidad/trunk_1.2.x/trinidad-partial-lifecycle/src/main/java/org/apache/myfaces/trinidadinternal/lifecycle/UIViewRoot.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk_1.2.x/trinidad-partial-lifecycle/src/main/java/org/apache/myfaces/trinidadinternal/lifecycle/UIViewRoot.java?rev=707969&view=auto
==============================================================================
--- myfaces/trinidad/trunk_1.2.x/trinidad-partial-lifecycle/src/main/java/org/apache/myfaces/trinidadinternal/lifecycle/UIViewRoot.java
(added)
+++ myfaces/trinidad/trunk_1.2.x/trinidad-partial-lifecycle/src/main/java/org/apache/myfaces/trinidadinternal/lifecycle/UIViewRoot.java
Sun Oct 26 04:41:03 2008
@@ -0,0 +1,312 @@
+package org.apache.myfaces.trinidadinternal.lifecycle;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.myfaces.trinidad.logging.TrinidadLogger;
+
+import javax.el.MethodExpression;
+import javax.faces.FactoryFinder;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.FacesEvent;
+import javax.faces.event.PhaseEvent;
+import javax.faces.event.PhaseId;
+import javax.faces.event.PhaseListener;
+import javax.faces.lifecycle.Lifecycle;
+import javax.faces.lifecycle.LifecycleFactory;
+import javax.faces.webapp.FacesServlet;
+import java.util.ArrayList;
+import java.util.ConcurrentModificationException;
+import java.util.List;
+import java.util.ListIterator;
+
+public class UIViewRoot extends javax.faces.component.UIViewRoot
+{
+  private static final TrinidadLogger LOG = TrinidadLogger.createTrinidadLogger(UIViewRoot.class);
+  public static final int ANY_PHASE_ORDINAL = PhaseId.ANY_PHASE.getOrdinal();
+
+  private List<FacesEvent> _events;
+  private List<PhaseListener> _phaseListeners;
+
+  private transient Lifecycle _lifecycle = null;
+
+  public void addPhaseListener(PhaseListener phaseListener)
+  {
+    if (phaseListener == null)
+    {
+      throw new NullPointerException("phaseListener");
+    }
+    if (_phaseListeners == null)
+    {
+      _phaseListeners = new ArrayList<PhaseListener>();
+    }
+
+    _phaseListeners.add(phaseListener);
+  }
+
+  /**
+   * Removes a The phaseListeners attached to ViewRoot.
+   */
+  public void removePhaseListener(PhaseListener phaseListener)
+  {
+    if (phaseListener == null || _phaseListeners == null)
+    {
+      return;
+    }
+
+    _phaseListeners.remove(phaseListener);
+  }
+
+  public void queueEvent(FacesEvent event)
+  {
+    if (_events == null)
+    {
+      _events = new ArrayList<FacesEvent>();
+    }
+    _events.add(event);
+  }
+
+  void broadcastForPhase(PhaseId phaseId)
+  {
+    if (_events == null)
+    {
+      return;
+    }
+
+    boolean abort = false;
+
+    int phaseIdOrdinal = phaseId.getOrdinal();
+    for (ListIterator<FacesEvent> listiterator = _events.listIterator(); listiterator
+        .hasNext();)
+    {
+      FacesEvent event = listiterator.next();
+      int ordinal = event.getPhaseId().getOrdinal();
+      if (ordinal == ANY_PHASE_ORDINAL || ordinal == phaseIdOrdinal)
+      {
+        UIComponent source = event.getComponent();
+        try
+        {
+          source.broadcast(event);
+        }
+        catch (AbortProcessingException e)
+        {
+          // abort event processing
+          // Page 3-30 of JSF 1.1 spec: "Throw an
+          // AbortProcessingException, to tell the JSF implementation
+          // that no further broadcast of this event, or any further
+          // events, should take place."
+          abort = true;
+          break;
+        }
+        finally
+        {
+          try
+          {
+            listiterator.remove();
+          }
+          catch (ConcurrentModificationException cme)
+          {
+            int eventIndex = listiterator.previousIndex();
+            _events.remove(eventIndex);
+            listiterator = _events.listIterator();
+          }
+        }
+      }
+    }
+
+    if (abort)
+    {
+      // TODO: abort processing of any event of any phase or just of any
+      // event of the current phase???
+      clearEvents();
+    }
+  }
+
+  private void clearEvents()
+  {
+    _events = null;
+  }
+
+  boolean notifyListeners(FacesContext context, PhaseId phaseId,
+      MethodExpression listener, boolean beforePhase)
+  {
+    boolean skipPhase = false;
+
+    if (listener != null
+        || (_phaseListeners != null && !_phaseListeners.isEmpty()))
+    {
+      PhaseEvent event = createEvent(context, phaseId);
+
+      if (listener != null)
+      {
+        listener.invoke(context.getELContext(), new Object[]
+            {event});
+        skipPhase = context.getResponseComplete()
+            || context.getRenderResponse();
+      }
+
+      if (_phaseListeners != null && !_phaseListeners.isEmpty())
+      {
+        for (PhaseListener phaseListener : _phaseListeners)
+        {
+          PhaseId listenerPhaseId = phaseListener.getPhaseId();
+          if (phaseId.equals(listenerPhaseId)
+              || PhaseId.ANY_PHASE.equals(listenerPhaseId))
+          {
+            if (beforePhase)
+            {
+              phaseListener.beforePhase(event);
+            } else
+            {
+              phaseListener.afterPhase(event);
+            }
+            skipPhase = context.getResponseComplete()
+                || context.getRenderResponse();
+          }
+        }
+      }
+    }
+
+    return skipPhase;
+  }
+
+  private PhaseEvent createEvent(FacesContext context, PhaseId phaseId)
+  {
+    if (_lifecycle == null)
+    {
+      LifecycleFactory factory = (LifecycleFactory) FactoryFinder
+          .getFactory(FactoryFinder.LIFECYCLE_FACTORY);
+      String id = context.getExternalContext().getInitParameter(
+          FacesServlet.LIFECYCLE_ID_ATTR);
+      if (id == null)
+      {
+        id = LifecycleFactory.DEFAULT_LIFECYCLE;
+      }
+      _lifecycle = factory.getLifecycle(id);
+    }
+    return new PhaseEvent(context, phaseId, _lifecycle);
+  }
+
+  public void processDecodes(FacesContext context)
+  {
+    if (!notifyListeners(context, PhaseId.APPLY_REQUEST_VALUES, getBeforePhaseListener(),
true))
+    {
+      super.processDecodes(context);
+
+      broadcastForPhase(PhaseId.APPLY_REQUEST_VALUES);
+    }
+    clearEvents(context);
+    notifyListeners(context, PhaseId.APPLY_REQUEST_VALUES, getAfterPhaseListener(), false);
+  }
+
+  void clearEvents(FacesContext context)
+  {
+    if (context.getRenderResponse() || context.getResponseComplete())
+    {
+      clearEvents();
+    }
+  }
+
+  public void processValidators(FacesContext context)
+  {
+    if (!notifyListeners(context, PhaseId.PROCESS_VALIDATIONS, getBeforePhaseListener(),
true))
+    {
+      super.processValidators(context);
+
+      broadcastForPhase(PhaseId.PROCESS_VALIDATIONS);
+    }
+    clearEvents(context);
+    notifyListeners(context, PhaseId.PROCESS_VALIDATIONS, getAfterPhaseListener(), false);
+  }
+
+  public void processUpdates(FacesContext context)
+  {
+    if (!notifyListeners(context, PhaseId.UPDATE_MODEL_VALUES, getBeforePhaseListener(),
true))
+    {
+      super.processUpdates(context);
+      broadcastForPhase(PhaseId.UPDATE_MODEL_VALUES);
+    }
+    clearEvents(context);
+    notifyListeners(context, PhaseId.UPDATE_MODEL_VALUES, getAfterPhaseListener(), false);
+  }
+
+  public void processApplication(FacesContext context)
+  {
+    if (!notifyListeners(context, PhaseId.INVOKE_APPLICATION, getBeforePhaseListener(), true))
+    {
+      broadcastForPhase(PhaseId.INVOKE_APPLICATION);
+    }
+    clearEvents(context);
+    notifyListeners(context, PhaseId.INVOKE_APPLICATION, getAfterPhaseListener(), false);
+  }
+
+  public void encodeBegin(FacesContext context) throws java.io.IOException
+  {
+
+    boolean skipPhase = false;
+
+    try
+    {
+      skipPhase = notifyListeners(context, PhaseId.RENDER_RESPONSE,
+          getBeforePhaseListener(), true);
+    }
+    catch (Exception e)
+    {
+      // following the spec we have to swallow the exception
+      LOG.severe("Exception while processing phase listener: " + e.getMessage(), e);
+    }
+
+    if (!skipPhase)
+    {
+      super.encodeBegin(context);
+    }
+  }
+
+  public void encodeEnd(FacesContext context) throws java.io.IOException
+  {
+    super.encodeEnd(context);
+    try
+    {
+      notifyListeners(context, PhaseId.RENDER_RESPONSE,
+          getAfterPhaseListener(), false);
+    }
+    catch (Exception e)
+    {
+      // following the spec we have to swallow the exception
+      LOG.severe("Exception while processing phase listener: " + e.getMessage(), e);
+    }
+  }
+
+  public Object saveState(FacesContext facesContext)
+  {
+    Object[] values = new Object[2];
+    values[0] = super.saveState(facesContext);
+    values[1] = saveAttachedState(facesContext, _phaseListeners);
+    return values;
+  }
+
+  @Override
+  public void restoreState(FacesContext facesContext, Object state)
+  {
+    Object[] values = (Object[]) state;
+    super.restoreState(facesContext, values[0]);
+    _phaseListeners = (List) restoreAttachedState(facesContext, values[1]);
+  }
+
+}

Propchange: myfaces/trinidad/trunk_1.2.x/trinidad-partial-lifecycle/src/main/java/org/apache/myfaces/trinidadinternal/lifecycle/UIViewRoot.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/trinidad/trunk_1.2.x/trinidad-partial-lifecycle/src/main/java/org/apache/myfaces/trinidadinternal/lifecycle/UIViewRoot.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: myfaces/trinidad/trunk_1.2.x/trinidad-partial-lifecycle/src/main/java/org/apache/myfaces/trinidadinternal/lifecycle/UpdateModelValuesExecutor.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk_1.2.x/trinidad-partial-lifecycle/src/main/java/org/apache/myfaces/trinidadinternal/lifecycle/UpdateModelValuesExecutor.java?rev=707969&r1=707968&r2=707969&view=diff
==============================================================================
--- myfaces/trinidad/trunk_1.2.x/trinidad-partial-lifecycle/src/main/java/org/apache/myfaces/trinidadinternal/lifecycle/UpdateModelValuesExecutor.java
(original)
+++ myfaces/trinidad/trunk_1.2.x/trinidad-partial-lifecycle/src/main/java/org/apache/myfaces/trinidadinternal/lifecycle/UpdateModelValuesExecutor.java
Sun Oct 26 04:41:03 2008
@@ -30,15 +30,19 @@
   public boolean execute(FacesContext facesContext)
   {
     String[] partialTargets = PartialLifecycleUtils.getPartialTargets(facesContext);
-    if (partialTargets != null)
+    if (partialTargets != null && facesContext.getViewRoot() instanceof UIViewRoot)
     {
-      for (String clientId : partialTargets)
+      UIViewRoot viewRoot = (UIViewRoot) facesContext.getViewRoot();
+      if (!viewRoot.notifyListeners(facesContext, PhaseId.UPDATE_MODEL_VALUES, viewRoot.getBeforePhaseListener(),
true))
       {
-        facesContext.getViewRoot().invokeOnComponent(facesContext, clientId, contextCallback);
+        for (String clientId : partialTargets)
+        {
+          facesContext.getViewRoot().invokeOnComponent(facesContext, clientId, contextCallback);
+        }
+        viewRoot.broadcastForPhase(PhaseId.UPDATE_MODEL_VALUES);
       }
-      //UIViewRoot viewRoot = facesContext.getViewRoot();
-      // TODO broadcast Events UIViewRoot has no public method
-      //viewRoot.broadcastEventsForPhase(facesContext, PhaseId.UPDATE_MODEL_VALUES);
+      viewRoot.clearEvents(facesContext);
+      viewRoot.notifyListeners(facesContext, PhaseId.UPDATE_MODEL_VALUES, viewRoot.getBeforePhaseListener(),
false);
     } else
     {
       facesContext.getViewRoot().processUpdates(facesContext);

Added: myfaces/trinidad/trunk_1.2.x/trinidad-partial-lifecycle/src/main/resources/META-INF/faces-config.xml
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk_1.2.x/trinidad-partial-lifecycle/src/main/resources/META-INF/faces-config.xml?rev=707969&view=auto
==============================================================================
--- myfaces/trinidad/trunk_1.2.x/trinidad-partial-lifecycle/src/main/resources/META-INF/faces-config.xml
(added)
+++ myfaces/trinidad/trunk_1.2.x/trinidad-partial-lifecycle/src/main/resources/META-INF/faces-config.xml
Sun Oct 26 04:41:03 2008
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+
+<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
+              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+              xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
+              version="1.2">
+  <component>
+    <component-type>javax.faces.ViewRoot</component-type>
+    <component-class>org.apache.myfaces.trinidadinternal.lifecycle.UIViewRoot</component-class>
+    <property>
+         <description><![CDATA[The locale for this view.
+<p>
+Defaults to the default locale specified in the faces configuration file.
+</p>]]></description>
+         <property-name>locale</property-name>
+         <property-class>java.util.Locale</property-class>
+    </property>
+    <property>
+         <description><![CDATA[Defines what renderkit should be used to render this
view.]]></description>
+         <property-name>renderKitId</property-name>
+         <property-class>java.lang.String</property-class>
+    </property>
+    <property>
+         <description><![CDATA[MethodBinding pointing to a method that takes a
+javax.faces.event.PhaseEvent and returns void,
+called before every phase except for restore view.]]></description>
+         <property-name>beforePhaseListener</property-name>
+         <property-class>javax.el.MethodExpression</property-class>
+    </property>
+    <property>
+         <description><![CDATA[MethodBinding pointing to a method that takes a
+javax.faces.event.PhaseEvent and returns void,
+called after every phase except for restore view.]]></description>
+         <property-name>afterPhaseListener</property-name>
+         <property-class>javax.el.MethodExpression</property-class>
+    </property>
+    <property>
+         <property-name>transient</property-name>
+         <property-class>boolean</property-class>
+    </property>
+  </component>
+</faces-config>
\ No newline at end of file

Propchange: myfaces/trinidad/trunk_1.2.x/trinidad-partial-lifecycle/src/main/resources/META-INF/faces-config.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/trinidad/trunk_1.2.x/trinidad-partial-lifecycle/src/main/resources/META-INF/faces-config.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL



Mime
View raw message