You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by im...@apache.org on 2008/03/27 11:33:21 UTC

svn commit: r641769 - /myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/

Author: imario
Date: Thu Mar 27 03:33:16 2008
New Revision: 641769

URL: http://svn.apache.org/viewvc?rev=641769&view=rev
Log:
reformat, relayout only

Modified:
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PPRPanelGroup.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PPRPanelGroupRenderer.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PPRPanelGroupTag.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PPRPhaseListener.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PPRSubmitRenderer.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PPRSupport.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PartialTriggerParser.java

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PPRPanelGroup.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PPRPanelGroup.java?rev=641769&r1=641768&r2=641769&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PPRPanelGroup.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PPRPanelGroup.java Thu Mar 27 03:33:16 2008
@@ -18,16 +18,13 @@
  */
 package org.apache.myfaces.custom.ppr;
 
-import javax.faces.context.FacesContext;
-import javax.faces.el.ValueBinding;
-import javax.faces.component.UIComponent;
-
 import org.apache.myfaces.component.html.ext.HtmlPanelGroup;
 import org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils;
-import org.apache.myfaces.custom.subform.SubForm;
 
-import java.util.List;
+import javax.faces.context.FacesContext;
+import javax.faces.el.ValueBinding;
 import java.util.Collections;
+import java.util.List;
 
 /**
  * AJAX component which supports updating its children via AJAX calls. These
@@ -35,219 +32,188 @@
  *
  * @author Ernst Fastl
  */
-public class PPRPanelGroup extends HtmlPanelGroup
-{
-	public static final String COMPONENT_TYPE = "org.apache.myfaces.PPRPanelGroup";
-
-	public static final String COMPONENT_FAMILY = "org.apache.myfaces.PPRPanelGroup";
-
-	public static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.PPRPanelGroup";
-
-	private String _partialTriggers;
-
-	private Integer _periodicalUpdate;
-
-	private String _periodicalTriggers;
-
-	private String _excludeFromStoppingPeriodicalUpdate;
-
-	private Integer _waitBeforePeriodicalUpdate = new Integer(2000);
-
-	private String _partialTriggerPattern;
-
-	private String _inlineLoadingMessage;
-
-	private Boolean _showDebugMessages = new Boolean(false);
-
-	private Boolean _stateUpdate = new Boolean(true);
-
-    public PPRPanelGroup()
-	{
-		setRendererType(DEFAULT_RENDERER_TYPE);
-	}
-
-	public String getFamily()
-	{
-		return COMPONENT_FAMILY;
-	}
-
-	public String getPartialTriggers()
-	{
-		if(_partialTriggers != null)
-		{
-			return _partialTriggers;
-		}
-		ValueBinding vb = getValueBinding("partialTriggers");
-		return vb != null ? RendererUtils.getStringValue(getFacesContext(), vb) : null;
-	}
-
-	public void setPartialTriggers(String partialTriggers)
-	{
-		this._partialTriggers = partialTriggers;
-	}
-
-	public Integer getPeriodicalUpdate()
-	{
-		if(_periodicalUpdate != null)
-		{
-			return _periodicalUpdate;
-		}
-		ValueBinding vb = getValueBinding("periodicalUpdate");
-		return (vb != null) ? (Integer) vb.getValue(getFacesContext()) : null;
-	}
-
-	public void setPeriodicalUpdate(Integer periodicalUpdate)
-	{
-		_periodicalUpdate = periodicalUpdate;
-	}
-
-	public String getPeriodicalTriggers()
-	{
-		if(_periodicalTriggers != null)
-		{
-			return _periodicalTriggers;
-		}
-		ValueBinding vb = getValueBinding("periodicalTriggers");
-		return (vb != null) ? (String) vb.getValue(getFacesContext()) : null;
-	}
-
-	public void setPeriodicalTriggers(String periodicalTriggers)
-	{
-		_periodicalTriggers = periodicalTriggers;
-	}
-
-	public String getPartialTriggerPattern()
-	{
-		if(_partialTriggerPattern != null)
-		{
-			return _partialTriggerPattern;
-		}
-		ValueBinding vb = getValueBinding("partialTriggerPattern");
-		return vb != null ? RendererUtils.getStringValue(getFacesContext(), vb) : null;
-	}
-
-	public void setPartialTriggerPattern(String partialTriggerPattern)
-	{
-		this._partialTriggerPattern = partialTriggerPattern;
-	}
-
-	public String getExcludeFromStoppingPeriodicalUpdate()
-	{
-		if(_excludeFromStoppingPeriodicalUpdate != null)
-		{
-			return _excludeFromStoppingPeriodicalUpdate;
-		}
-		ValueBinding vb = getValueBinding("excludeFromStoppingPeriodicalUpdate");
-		return vb != null ? RendererUtils.getStringValue(getFacesContext(), vb) : null;
-	}
-
-	public void setExcludeFromStoppingPeriodicalUpdate(String excludeFromStoppingPeriodicalUpdate)
-	{
-		_excludeFromStoppingPeriodicalUpdate = excludeFromStoppingPeriodicalUpdate;
-	}
-
-	public Integer getWaitBeforePeriodicalUpdate()
-	{
-		if(_waitBeforePeriodicalUpdate != null)
-		{
-			return _waitBeforePeriodicalUpdate;
-		}
-		ValueBinding vb = getValueBinding("waitBeforePeriodicalUpdate");
-		return (vb != null) ? (Integer) vb.getValue(getFacesContext()) : null;
-	}
-
-	public void setWaitBeforePeriodicalUpdate(Integer waitBeforePeriodicalUpdate)
-	{
-		_waitBeforePeriodicalUpdate = waitBeforePeriodicalUpdate;
-	}
-
-	public String getInlineLoadingMessage()
-	{
-		if(_inlineLoadingMessage != null)
-		{
-			return _inlineLoadingMessage;
-		}
-		ValueBinding vb = getValueBinding("inlineLoadingMessage");
-		return vb != null ? RendererUtils.getStringValue(getFacesContext(), vb) : null;
-	}
-
-	public void setInlineLoadingMessage(String inlineLoadingMessage)
-	{
-		this._inlineLoadingMessage = inlineLoadingMessage;
-	}
-
-	public Boolean getShowDebugMessages()
-	{
-		if(_showDebugMessages != null)
-		{
-			return _showDebugMessages;
-		}
-		ValueBinding vb = getValueBinding("showDebugMessages");
-		return vb != null ? (Boolean) vb.getValue(getFacesContext()) : null;
-	}
-
-	public void setShowDebugMessages(Boolean showDebugMessages)
-	{
-		_showDebugMessages = showDebugMessages;
-	}
-
-	public Boolean getStateUpdate()
-	{
-		if(_stateUpdate != null)
-		{
-			return _stateUpdate;
-		}
-		ValueBinding vb = getValueBinding("stateUpdate");
-		return vb != null ? (Boolean) vb.getValue(getFacesContext()) : null;
-	}
-
-	public void setStateUpdate(Boolean stateUpdate)
-	{
-		_stateUpdate = stateUpdate;
-	}
-
-	public void restoreState(FacesContext context, Object state)
-	{
-		Object[] values = (Object[]) state;
-		super.restoreState(context, values[0]);
-		_partialTriggers = (String) values[1];
-		_partialTriggerPattern = (String) values[2];
-		_periodicalUpdate = (Integer) values[3];
-		_periodicalTriggers = (String) values[4];
-		_showDebugMessages = (Boolean) values[5];
-		_stateUpdate = (Boolean) values[6];
-		_excludeFromStoppingPeriodicalUpdate = (String) values[7];
-		_waitBeforePeriodicalUpdate = (Integer) values[8];
-	}
-
-	public Object saveState(FacesContext context)
-	{
-		Object[] values = new Object[9];
-		values[0] = super.saveState(context);
-		values[1] = _partialTriggers;
-		values[2] = _partialTriggerPattern;
-		values[3] = _periodicalUpdate;
-		values[4] = _periodicalTriggers;
-		values[5] = _showDebugMessages;
-		values[6] = _stateUpdate;
-		values[7] = _excludeFromStoppingPeriodicalUpdate;
-		values[8] = _waitBeforePeriodicalUpdate;
-		return values;
-	}
+public class PPRPanelGroup extends HtmlPanelGroup {
+    public static final String COMPONENT_TYPE = "org.apache.myfaces.PPRPanelGroup";
+
+    public static final String COMPONENT_FAMILY = "org.apache.myfaces.PPRPanelGroup";
+
+    public static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.PPRPanelGroup";
+
+    private String _partialTriggers;
+
+    private Integer _periodicalUpdate;
+
+    private String _periodicalTriggers;
+
+    private String _excludeFromStoppingPeriodicalUpdate;
+
+    private Integer _waitBeforePeriodicalUpdate = new Integer(2000);
+
+    private String _partialTriggerPattern;
+
+    private String _inlineLoadingMessage;
+
+    private Boolean _showDebugMessages = new Boolean(false);
+
+    private Boolean _stateUpdate = new Boolean(true);
+
+    public PPRPanelGroup() {
+        setRendererType(DEFAULT_RENDERER_TYPE);
+    }
+
+    public String getFamily() {
+        return COMPONENT_FAMILY;
+    }
+
+    public String getPartialTriggers() {
+        if (_partialTriggers != null) {
+            return _partialTriggers;
+        }
+        ValueBinding vb = getValueBinding("partialTriggers");
+        return vb != null ? RendererUtils.getStringValue(getFacesContext(), vb) : null;
+    }
+
+    public void setPartialTriggers(String partialTriggers) {
+        this._partialTriggers = partialTriggers;
+    }
+
+    public Integer getPeriodicalUpdate() {
+        if (_periodicalUpdate != null) {
+            return _periodicalUpdate;
+        }
+        ValueBinding vb = getValueBinding("periodicalUpdate");
+        return (vb != null) ? (Integer) vb.getValue(getFacesContext()) : null;
+    }
+
+    public void setPeriodicalUpdate(Integer periodicalUpdate) {
+        _periodicalUpdate = periodicalUpdate;
+    }
+
+    public String getPeriodicalTriggers() {
+        if (_periodicalTriggers != null) {
+            return _periodicalTriggers;
+        }
+        ValueBinding vb = getValueBinding("periodicalTriggers");
+        return (vb != null) ? (String) vb.getValue(getFacesContext()) : null;
+    }
+
+    public void setPeriodicalTriggers(String periodicalTriggers) {
+        _periodicalTriggers = periodicalTriggers;
+    }
+
+    public String getPartialTriggerPattern() {
+        if (_partialTriggerPattern != null) {
+            return _partialTriggerPattern;
+        }
+        ValueBinding vb = getValueBinding("partialTriggerPattern");
+        return vb != null ? RendererUtils.getStringValue(getFacesContext(), vb) : null;
+    }
+
+    public void setPartialTriggerPattern(String partialTriggerPattern) {
+        this._partialTriggerPattern = partialTriggerPattern;
+    }
+
+    public String getExcludeFromStoppingPeriodicalUpdate() {
+        if (_excludeFromStoppingPeriodicalUpdate != null) {
+            return _excludeFromStoppingPeriodicalUpdate;
+        }
+        ValueBinding vb = getValueBinding("excludeFromStoppingPeriodicalUpdate");
+        return vb != null ? RendererUtils.getStringValue(getFacesContext(), vb) : null;
+    }
+
+    public void setExcludeFromStoppingPeriodicalUpdate(String excludeFromStoppingPeriodicalUpdate) {
+        _excludeFromStoppingPeriodicalUpdate = excludeFromStoppingPeriodicalUpdate;
+    }
+
+    public Integer getWaitBeforePeriodicalUpdate() {
+        if (_waitBeforePeriodicalUpdate != null) {
+            return _waitBeforePeriodicalUpdate;
+        }
+        ValueBinding vb = getValueBinding("waitBeforePeriodicalUpdate");
+        return (vb != null) ? (Integer) vb.getValue(getFacesContext()) : null;
+    }
+
+    public void setWaitBeforePeriodicalUpdate(Integer waitBeforePeriodicalUpdate) {
+        _waitBeforePeriodicalUpdate = waitBeforePeriodicalUpdate;
+    }
+
+    public String getInlineLoadingMessage() {
+        if (_inlineLoadingMessage != null) {
+            return _inlineLoadingMessage;
+        }
+        ValueBinding vb = getValueBinding("inlineLoadingMessage");
+        return vb != null ? RendererUtils.getStringValue(getFacesContext(), vb) : null;
+    }
+
+    public void setInlineLoadingMessage(String inlineLoadingMessage) {
+        this._inlineLoadingMessage = inlineLoadingMessage;
+    }
+
+    public Boolean getShowDebugMessages() {
+        if (_showDebugMessages != null) {
+            return _showDebugMessages;
+        }
+        ValueBinding vb = getValueBinding("showDebugMessages");
+        return vb != null ? (Boolean) vb.getValue(getFacesContext()) : null;
+    }
+
+    public void setShowDebugMessages(Boolean showDebugMessages) {
+        _showDebugMessages = showDebugMessages;
+    }
+
+    public Boolean getStateUpdate() {
+        if (_stateUpdate != null) {
+            return _stateUpdate;
+        }
+        ValueBinding vb = getValueBinding("stateUpdate");
+        return vb != null ? (Boolean) vb.getValue(getFacesContext()) : null;
+    }
+
+    public void setStateUpdate(Boolean stateUpdate) {
+        _stateUpdate = stateUpdate;
+    }
+
+    public void restoreState(FacesContext context, Object state) {
+        Object[] values = (Object[]) state;
+        super.restoreState(context, values[0]);
+        _partialTriggers = (String) values[1];
+        _partialTriggerPattern = (String) values[2];
+        _periodicalUpdate = (Integer) values[3];
+        _periodicalTriggers = (String) values[4];
+        _showDebugMessages = (Boolean) values[5];
+        _stateUpdate = (Boolean) values[6];
+        _excludeFromStoppingPeriodicalUpdate = (String) values[7];
+        _waitBeforePeriodicalUpdate = (Integer) values[8];
+    }
+
+    public Object saveState(FacesContext context) {
+        Object[] values = new Object[9];
+        values[0] = super.saveState(context);
+        values[1] = _partialTriggers;
+        values[2] = _partialTriggerPattern;
+        values[3] = _periodicalUpdate;
+        values[4] = _periodicalTriggers;
+        values[5] = _showDebugMessages;
+        values[6] = _stateUpdate;
+        values[7] = _excludeFromStoppingPeriodicalUpdate;
+        values[8] = _waitBeforePeriodicalUpdate;
+        return values;
+    }
 
 
     /**
      * @return {@link PartialTriggerParser.PartialTrigger}
      */
-    public List parsePartialTriggers () {
+    public List parsePartialTriggers() {
         List list;
-            String partialTriggers = getPartialTriggers();
-            //handle partial triggers
-            if(partialTriggers != null && partialTriggers.trim().length() > 0) {
-                list = (new PartialTriggerParser()).parse(partialTriggers);
-            } else {
-                list = Collections.emptyList();
-            }
+        String partialTriggers = getPartialTriggers();
+        //handle partial triggers
+        if (partialTriggers != null && partialTriggers.trim().length() > 0) {
+            list = (new PartialTriggerParser()).parse(partialTriggers);
+        }
+        else {
+            list = Collections.emptyList();
+        }
         return list;
     }
 
@@ -257,9 +223,10 @@
     public List parsePeriodicalTriggers() {
         List list;
         String periodicalTriggers = getPeriodicalTriggers();
-        if(periodicalTriggers != null && periodicalTriggers.trim().length() <= 0) {
+        if (periodicalTriggers != null && periodicalTriggers.trim().length() <= 0) {
             list = (new PartialTriggerParser()).parse(periodicalTriggers);
-        } else {
+        }
+        else {
             list = Collections.emptyList();
         }
         return list;

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PPRPanelGroupRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PPRPanelGroupRenderer.java?rev=641769&r1=641768&r2=641769&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PPRPanelGroupRenderer.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PPRPanelGroupRenderer.java Thu Mar 27 03:33:16 2008
@@ -30,105 +30,95 @@
 /**
  * @author Ernst Fastl
  */
-public class PPRPanelGroupRenderer extends HtmlGroupRenderer
-{
-	//private static Log log = LogFactory.getLog(PPRPanelGroupRenderer.class);
+public class PPRPanelGroupRenderer extends HtmlGroupRenderer {
+    //private static Log log = LogFactory.getLog(PPRPanelGroupRenderer.class);
 
     private static final String DISABLE_RENDER_CHILDREN = "org.apache.myfaces.PPRPanelGroup.disableRenderChildren";
 
     public static final String TRANSIENT_MARKER_ATTRIBUTE = "org.apache.myfaces.PPRPanelGroup.transientComponent";
 
     /**
-	 * Renders the start of a span element. Iterates over all child
-	 * components and sets transient components to transient=false. Those
-	 * components are marked with the TRANSIENT_MARKER_ATTRIBUTE so the
-	 * {@link PPRPhaseListener} can reset them to transient in the next
-	 * non-PPR Request
-	 *
-	 * @param facesContext the current {@link FacesContext}
-	 * @param uiComponent  the {@link PPRPanelGroup} to render
-	 */
-	public void encodeBegin(FacesContext facesContext, UIComponent uiComponent) throws IOException
-	{
-		if(uiComponent.getId() == null || uiComponent.getId().startsWith(UIViewRoot.UNIQUE_ID_PREFIX))
-		{
-			throw new IllegalArgumentException("'id' is a required attribute for the PPRPanelGroup");
-		}
-
-		// todo: in 1.2, better use a combo of
-		// invokeComponent/RendererUtils.renderChildren() instead
-		uiComponent.getAttributes().put(DISABLE_RENDER_CHILDREN, Boolean.TRUE);
-
-		// Iterate over the transient child components and set transient to
-		// false
-		// This is necessary to have those components available for PPR
-		// responses later on
-		for(Iterator iter = uiComponent.getChildren().iterator(); iter.hasNext();)
-		{
-			UIComponent child = (UIComponent) iter.next();
-			if(child.isTransient())
-			{
-				child.setTransient(false);
-				child.getAttributes().put(TRANSIENT_MARKER_ATTRIBUTE, Boolean.TRUE);
-			}
-		}
-
-		super.encodeBegin(facesContext, uiComponent);
-	}
-
-	/**
-	 * todo: in 1.2, better use a combo of
-	 * invokeComponent/RendererUtils.renderChildren() instead
-	 *
-	 * @param context
-	 * @param component
-	 * @throws IOException
-	 */
-	public void encodeChildren(FacesContext context, UIComponent component) throws IOException
-	{
-		Boolean disableRenderChildren = (Boolean) component.getAttributes().get(DISABLE_RENDER_CHILDREN);
-
-		if(disableRenderChildren == null || disableRenderChildren.booleanValue() == false)
-		{
-			RendererUtils.renderChildren(context, component);
-		}
-	}
-
-	/**
-	 * Encodes the end of the span-element and afterwards the inline
-	 * JavaScript for the client side initialization of the
-	 * {@link PPRPanelGroup}.
-	 *
-	 * @param facesContext the current {@link FacesContext}
-	 * @param uiComponent  the {@link PPRPanelGroup} to render
-	 */
-	public void encodeEnd(FacesContext facesContext, UIComponent uiComponent) throws IOException
-	{
-		// Render the span end element
-		super.encodeEnd(facesContext, uiComponent);
-		if(uiComponent instanceof PPRPanelGroup)
-		{
-			PPRPanelGroup pprGroup = (PPRPanelGroup) uiComponent;
-
-			final String triggers = pprGroup.getPartialTriggers();
-			final String triggerPattern = pprGroup.getPartialTriggerPattern();
-
-			// Check if triggers, a pattern or a periodical update is
-			// defined
-			if((triggers != null && triggers.length() > 0) || (triggerPattern != null && triggerPattern.length() > 0) || pprGroup.getPeriodicalUpdate() != null)
-			{
-                if(PPRSupport.isPartialRequest(facesContext)) {
+     * Renders the start of a span element. Iterates over all child
+     * components and sets transient components to transient=false. Those
+     * components are marked with the TRANSIENT_MARKER_ATTRIBUTE so the
+     * {@link PPRPhaseListener} can reset them to transient in the next
+     * non-PPR Request
+     *
+     * @param facesContext the current {@link FacesContext}
+     * @param uiComponent  the {@link PPRPanelGroup} to render
+     */
+    public void encodeBegin(FacesContext facesContext, UIComponent uiComponent) throws IOException {
+        if (uiComponent.getId() == null || uiComponent.getId().startsWith(UIViewRoot.UNIQUE_ID_PREFIX)) {
+            throw new IllegalArgumentException("'id' is a required attribute for the PPRPanelGroup");
+        }
+
+        // todo: in 1.2, better use a combo of
+        // invokeComponent/RendererUtils.renderChildren() instead
+        uiComponent.getAttributes().put(DISABLE_RENDER_CHILDREN, Boolean.TRUE);
+
+        // Iterate over the transient child components and set transient to
+        // false
+        // This is necessary to have those components available for PPR
+        // responses later on
+        for (Iterator iter = uiComponent.getChildren().iterator(); iter.hasNext();) {
+            UIComponent child = (UIComponent) iter.next();
+            if (child.isTransient()) {
+                child.setTransient(false);
+                child.getAttributes().put(TRANSIENT_MARKER_ATTRIBUTE, Boolean.TRUE);
+            }
+        }
+
+        super.encodeBegin(facesContext, uiComponent);
+    }
+
+    /**
+     * todo: in 1.2, better use a combo of
+     * invokeComponent/RendererUtils.renderChildren() instead
+     *
+     * @param context
+     * @param component
+     * @throws IOException
+     */
+    public void encodeChildren(FacesContext context, UIComponent component) throws IOException {
+        Boolean disableRenderChildren = (Boolean) component.getAttributes().get(DISABLE_RENDER_CHILDREN);
+
+        if (disableRenderChildren == null || disableRenderChildren.booleanValue() == false) {
+            RendererUtils.renderChildren(context, component);
+        }
+    }
+
+    /**
+     * Encodes the end of the span-element and afterwards the inline
+     * JavaScript for the client side initialization of the
+     * {@link PPRPanelGroup}.
+     *
+     * @param facesContext the current {@link FacesContext}
+     * @param uiComponent  the {@link PPRPanelGroup} to render
+     */
+    public void encodeEnd(FacesContext facesContext, UIComponent uiComponent) throws IOException {
+        // Render the span end element
+        super.encodeEnd(facesContext, uiComponent);
+        if (uiComponent instanceof PPRPanelGroup) {
+            PPRPanelGroup pprGroup = (PPRPanelGroup) uiComponent;
+
+            final String triggers = pprGroup.getPartialTriggers();
+            final String triggerPattern = pprGroup.getPartialTriggerPattern();
+
+            // Check if triggers, a pattern or a periodical update is
+            // defined
+            if ((triggers != null && triggers.length() > 0) || (triggerPattern != null && triggerPattern.length() > 0) || pprGroup.getPeriodicalUpdate() != null) {
+                if (PPRSupport.isPartialRequest(facesContext)) {
                     return;
                 }
-				// encode the initialization inline JavaScript
+                // encode the initialization inline JavaScript
                 PPRSupport.initPPR(facesContext, pprGroup);
                 PPRSupport.encodeJavaScript(facesContext, pprGroup);
-			}
-		}
+            }
+        }
 
-		// todo: in 1.2, better use a combo of
-		// invokeComponent/RendererUtils.renderChildren() instead
-		uiComponent.getAttributes().put(DISABLE_RENDER_CHILDREN, Boolean.FALSE);
-	}
+        // todo: in 1.2, better use a combo of
+        // invokeComponent/RendererUtils.renderChildren() instead
+        uiComponent.getAttributes().put(DISABLE_RENDER_CHILDREN, Boolean.FALSE);
+    }
 
 }

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PPRPanelGroupTag.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PPRPanelGroupTag.java?rev=641769&r1=641768&r2=641769&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PPRPanelGroupTag.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PPRPanelGroupTag.java Thu Mar 27 03:33:16 2008
@@ -25,125 +25,107 @@
 /**
  * @author Ernst Fastl
  */
-public class PPRPanelGroupTag extends HtmlPanelGroupTag
-{
-	private String _partialTriggers;
-
-	private String _partialTriggerPattern;
-
-	private String _inlineLoadingMessage;
-
-	private String _periodicalUpdate;
-
-	private String _periodicalTriggers;
-
-	private String _excludeFromStoppingPeriodicalUpdate;
-
-	private String _showDebugMessages;
-
-	private String _stateUpdate;
-
-	private String _waitBeforePeriodicalUpdate;
-
-	public String getComponentType()
-	{
-		return PPRPanelGroup.COMPONENT_TYPE;
-	}
-
-	public String getRendererType()
-	{
-		return PPRPanelGroup.DEFAULT_RENDERER_TYPE;
-	}
-
-	public void release()
-	{
-		super.release();
-		_partialTriggers = null;
-		_periodicalUpdate = null;
-		_periodicalTriggers = null;
-		_showDebugMessages = null;
-		_stateUpdate = null;
-		_excludeFromStoppingPeriodicalUpdate = null;
-		_waitBeforePeriodicalUpdate = null;
-	}
-
-	protected void setProperties(UIComponent component)
-	{
-		super.setProperties(component);
-
-		setStringProperty(component, "partialTriggers", _partialTriggers);
-		setStringProperty(component, "partialTriggerPattern", _partialTriggerPattern);
-		setStringProperty(component, "inlineLoadingMessage", _inlineLoadingMessage);
-		setIntegerProperty(component, "periodicalUpdate", _periodicalUpdate);
-		setStringProperty(component, "periodicalTriggers", _periodicalTriggers);
-		setStringProperty(component, "excludeFromStoppingPeriodicalUpdate", _excludeFromStoppingPeriodicalUpdate);
-		setIntegerProperty(component, "waitBeforePeriodicalUpdate", _waitBeforePeriodicalUpdate);
-		setBooleanProperty(component, "showDebugMessages", _showDebugMessages);
-		setBooleanProperty(component, "stateUpdate", _stateUpdate);
-	}
-
-	public String getPartialTriggers()
-	{
-		return _partialTriggers;
-	}
-
-	public void setPartialTriggers(String partialTriggers)
-	{
-		this._partialTriggers = partialTriggers;
-	}
-
-	public String getPartialTriggerPattern()
-	{
-		return _partialTriggerPattern;
-	}
-
-	public void setPartialTriggerPattern(String triggerPattern)
-	{
-		_partialTriggerPattern = triggerPattern;
-	}
-
-	public String getInlineLoadingMessage()
-	{
-		return _inlineLoadingMessage;
-	}
-
-	public void setInlineLoadingMessage(String loadingMessage)
-	{
-		_inlineLoadingMessage = loadingMessage;
-	}
-
-	public void setPeriodicalUpdate(String periodicalUpdate)
-	{
-		_periodicalUpdate = periodicalUpdate;
-	}
-
-	public String getPeriodicalTriggers()
-	{
-		return _periodicalTriggers;
-	}
-
-	public void setPeriodicalTriggers(String periodicalTriggers)
-	{
-		_periodicalTriggers = periodicalTriggers;
-	}
-
-	public void setShowDebugMessages(String showDebugMessages)
-	{
-		_showDebugMessages = showDebugMessages;
-	}
-
-	public void setStateUpdate(String stateUpdate)
-	{
-		_stateUpdate = stateUpdate;
-	}
-
-	public void setExcludeFromStoppingPeriodicalUpdate(String excludeFromStoppingPeriodicalUpdate)
-	{
-		_excludeFromStoppingPeriodicalUpdate = excludeFromStoppingPeriodicalUpdate;
-	}
-
-	public void setWaitBeforePeriodicalUpdate(String waitBeforePeriodicalUpdate)
-	{
-		_waitBeforePeriodicalUpdate = waitBeforePeriodicalUpdate;
-	}
+public class PPRPanelGroupTag extends HtmlPanelGroupTag {
+    private String _partialTriggers;
+
+    private String _partialTriggerPattern;
+
+    private String _inlineLoadingMessage;
+
+    private String _periodicalUpdate;
+
+    private String _periodicalTriggers;
+
+    private String _excludeFromStoppingPeriodicalUpdate;
+
+    private String _showDebugMessages;
+
+    private String _stateUpdate;
+
+    private String _waitBeforePeriodicalUpdate;
+
+    public String getComponentType() {
+        return PPRPanelGroup.COMPONENT_TYPE;
+    }
+
+    public String getRendererType() {
+        return PPRPanelGroup.DEFAULT_RENDERER_TYPE;
+    }
+
+    public void release() {
+        super.release();
+        _partialTriggers = null;
+        _periodicalUpdate = null;
+        _periodicalTriggers = null;
+        _showDebugMessages = null;
+        _stateUpdate = null;
+        _excludeFromStoppingPeriodicalUpdate = null;
+        _waitBeforePeriodicalUpdate = null;
+    }
+
+    protected void setProperties(UIComponent component) {
+        super.setProperties(component);
+
+        setStringProperty(component, "partialTriggers", _partialTriggers);
+        setStringProperty(component, "partialTriggerPattern", _partialTriggerPattern);
+        setStringProperty(component, "inlineLoadingMessage", _inlineLoadingMessage);
+        setIntegerProperty(component, "periodicalUpdate", _periodicalUpdate);
+        setStringProperty(component, "periodicalTriggers", _periodicalTriggers);
+        setStringProperty(component, "excludeFromStoppingPeriodicalUpdate", _excludeFromStoppingPeriodicalUpdate);
+        setIntegerProperty(component, "waitBeforePeriodicalUpdate", _waitBeforePeriodicalUpdate);
+        setBooleanProperty(component, "showDebugMessages", _showDebugMessages);
+        setBooleanProperty(component, "stateUpdate", _stateUpdate);
+    }
+
+    public String getPartialTriggers() {
+        return _partialTriggers;
+    }
+
+    public void setPartialTriggers(String partialTriggers) {
+        this._partialTriggers = partialTriggers;
+    }
+
+    public String getPartialTriggerPattern() {
+        return _partialTriggerPattern;
+    }
+
+    public void setPartialTriggerPattern(String triggerPattern) {
+        _partialTriggerPattern = triggerPattern;
+    }
+
+    public String getInlineLoadingMessage() {
+        return _inlineLoadingMessage;
+    }
+
+    public void setInlineLoadingMessage(String loadingMessage) {
+        _inlineLoadingMessage = loadingMessage;
+    }
+
+    public void setPeriodicalUpdate(String periodicalUpdate) {
+        _periodicalUpdate = periodicalUpdate;
+    }
+
+    public String getPeriodicalTriggers() {
+        return _periodicalTriggers;
+    }
+
+    public void setPeriodicalTriggers(String periodicalTriggers) {
+        _periodicalTriggers = periodicalTriggers;
+    }
+
+    public void setShowDebugMessages(String showDebugMessages) {
+        _showDebugMessages = showDebugMessages;
+    }
+
+    public void setStateUpdate(String stateUpdate) {
+        _stateUpdate = stateUpdate;
+    }
+
+    public void setExcludeFromStoppingPeriodicalUpdate(String excludeFromStoppingPeriodicalUpdate) {
+        _excludeFromStoppingPeriodicalUpdate = excludeFromStoppingPeriodicalUpdate;
+    }
+
+    public void setWaitBeforePeriodicalUpdate(String waitBeforePeriodicalUpdate) {
+        _waitBeforePeriodicalUpdate = waitBeforePeriodicalUpdate;
+    }
 }

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PPRPhaseListener.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PPRPhaseListener.java?rev=641769&r1=641768&r2=641769&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PPRPhaseListener.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PPRPhaseListener.java Thu Mar 27 03:33:16 2008
@@ -18,11 +18,10 @@
  */
 package org.apache.myfaces.custom.ppr;
 
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.StringTokenizer;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRendererUtils;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlResponseWriterImpl;
 
 import javax.faces.FacesException;
 import javax.faces.application.StateManager;
@@ -35,11 +34,11 @@
 import javax.faces.event.PhaseListener;
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRendererUtils;
-import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlResponseWriterImpl;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.StringTokenizer;
 
 /**
  * Before RenderResponse PhaseListener for processing Ajax requests from
@@ -48,274 +47,243 @@
  *
  * @author Ernst Fastl
  */
-public class PPRPhaseListener implements PhaseListener
-{
-	private static Log log = LogFactory.getLog(PPRPhaseListener.class);
-
-	/**
-	 * Request parameter which marks a request as PPR request
-	 */
-	private static final String PPR_PARAMETER = "org.apache.myfaces.PPRCtrl.ajaxRequest";
-
-	/**
-	 * Request parameter containing a comma separated list of component IDs
-	 * of the to be updated components
-	 */
-	private static final String TRIGGERED_COMPONENTS_PARAMETER = "org.apache.myfaces.PPRCtrl.triggeredComponents";
-
-	private static final String XML_HEADER = "<?xml version=\"1.0\"?>\n";
-
-	public void afterPhase(PhaseEvent phaseEvent)
-	{
-	}
-
-	/**
-	 * Determines wether the currently processed request is a PPR request
-	 * (by searching for PPR_PARAMETER in the request parameter map) or an
-	 * ordinary HTTP request. If the request is a PPR request the triggered
-	 * components are encoded. Otherwise transient components which have
-	 * previously been marked not transient by the
-	 * {@link PPRPanelGroupRenderer} are set to transient again
-	 */
-	public void beforePhase(PhaseEvent event)
-	{
-		if(log.isDebugEnabled())
-		{
-			log.debug("In PPRPhaseListener beforePhase");
-		}
-
-		final FacesContext context = event.getFacesContext();
-		final ExternalContext externalContext = context.getExternalContext();
-
-		Map requestMap = externalContext.getRequestMap();
-
-		if(isPartialRequest(context))
-		{
-			processPartialPageRequest(context, externalContext, requestMap);
-		}
-		else
-		{
-			// Iterate over the component tree and set all previously
-			// transient components to transient again
-			resetTransientComponents(context.getViewRoot());
-		}
-	}
-
-	/**
-	 * if the provided component was marked transient in the last request
-	 * set it to transient. Recursively do the same for all children
-	 *
-	 * @param comp the component to reset
-	 */
-	private void resetTransientComponents(UIComponent comp)
-	{
-		if(comp.getAttributes().containsKey(PPRPanelGroupRenderer.TRANSIENT_MARKER_ATTRIBUTE))
-		{
-			comp.setTransient(true);
-		}
-		for(Iterator iter = comp.getChildren().iterator(); iter.hasNext();)
-		{
-			UIComponent child = (UIComponent) iter.next();
-			resetTransientComponents(child);
-		}
-	}
-
-	/**
-	 * Checks if the currently processed Request is an AJAX request from a
-	 * PPRPanelGroup
-	 *
-	 * @param context the current {@link FacesContext}
-	 * @return true if a PPR request is being processed , false otherwise
-	 */
-	public static boolean isPartialRequest(FacesContext context)
-	{
-		return context.getExternalContext().getRequestParameterMap().containsKey(PPR_PARAMETER);
-	}
-
-	/**
-	 * Respond to an AJAX request from a {@link PPRPanelGroup}. The
-	 * triggered components are determined by reading the
-	 * TRIGGERED_COMPONENTS_PARAMETER from either the RequestParameterMap or
-	 * the Request Map. Those componenets are encoded into an XML response.
-	 * The lifecycle is quit afterwards.
-	 *
-	 * @param context		 the current {@link FacesContext}
-	 * @param externalContext the current {@link ExternalContext}
-	 * @param requestMap	  Map containing the request attributes
-	 */
-	private void processPartialPageRequest(FacesContext context, final ExternalContext externalContext, Map requestMap)
-	{
-
-		ServletResponse response = (ServletResponse) externalContext.getResponse();
-		ServletRequest request = (ServletRequest) externalContext.getRequest();
-
-		UIViewRoot viewRoot = context.getViewRoot();
-
-		// Set Character encoding, contentType and locale for the response
-		final String characterEncoding = request.getCharacterEncoding();
-		String contentType = getContentType("text/xml", characterEncoding);
-		response.setContentType(contentType);
-		response.setLocale(viewRoot.getLocale());
-
-		// Fetch the comma-separated list of triggered components
-		String triggeredComponents = getTriggeredComponents(context);
-
-		try
-		{
-			PrintWriter out = response.getWriter();
-			context.setResponseWriter(new HtmlResponseWriterImpl(out, contentType, characterEncoding));
-			out.print(XML_HEADER);
-			out.print("<response>\n");
-			encodeTriggeredComponents(out, triggeredComponents, viewRoot, context);
-			out.print("</response>");
-			out.flush();
-		}
-		catch(IOException e)
-		{
-			throw new FacesException(e);
-		}
-
-		context.responseComplete();
-	}
-
-	/**
-	 * Fetch the comma-separated list of triggered components. They are
-	 * either obtained from the Request Parameter Map where they had
-	 * previously been set using
-	 * {@link PPRPhaseListener#addTriggeredComponent(FacesContext, String))
-	 * or from the request parameter map.
-	 *
-	 * @param fc the current {@link FacesContext}
-	 * @return a comma separated list of component IDs of the components
-	 *         which are to be updated
-	 */
-	private static String getTriggeredComponents(FacesContext fc)
-	{
-		String triggeredComponents = (String) fc.getExternalContext().getRequestMap().get(TRIGGERED_COMPONENTS_PARAMETER);
-
-		if(triggeredComponents == null)
-		{
-			triggeredComponents = (String) fc.getExternalContext().getRequestParameterMap().get(TRIGGERED_COMPONENTS_PARAMETER);
-		}
-
-		return triggeredComponents;
-	}
-
-	/**
-	 * API method for adding triggeredComponents programmatically.
-	 *
-	 * @param fc						 the current {@link FacesContext}
-	 * @param triggeredComponentClientId client ID of the component which is to be updated in
-	 *                                   case of a PPR Response
-	 */
-	public static void addTriggeredComponent(FacesContext fc, String triggeredComponentClientId)
-	{
-		String triggeredComponents = getTriggeredComponents(fc);
-
-		if(triggeredComponents == null || triggeredComponents.trim().length() == 0)
-		{
-			triggeredComponents = new String();
-		}
-		else
-		{
-			triggeredComponents = triggeredComponents + ",";
-		}
-
-		triggeredComponents = triggeredComponents + triggeredComponentClientId;
-
-		fc.getExternalContext().getRequestMap().put(TRIGGERED_COMPONENTS_PARAMETER, triggeredComponents);
-	}
-
-	/**
-	 * Generate content-type String either containing only the mime-type or
-	 * mime-type and character enconding.
-	 *
-	 * @param contentType the contentType/mimeType
-	 * @param charset	 the character set
-	 * @return the content-type String to be used in an HTTP response
-	 */
-	private String getContentType(String contentType, String charset)
-	{
-		if(charset == null || charset.trim().length() == 0)
-		{
-			return contentType;
-		}
-		else
-		{
-			return contentType + ";charset=" + charset;
-		}
-	}
-
-	/**
-	 * Writes the XML elements for the triggered components to the provided
-	 * {@link PrintWriter}. Also encode the current state in a separate XML
-	 * element.
-	 *
-	 * @param out				 the output Writer
-	 * @param triggeredComponents comma-separated list of component IDs
-	 * @param viewRoot			the current ViewRoot
-	 * @param context			 the current {@link FacesContext}
-	 */
-	private void encodeTriggeredComponents(PrintWriter out, String triggeredComponents, UIViewRoot viewRoot, FacesContext context)
-	{
-		StringTokenizer st = new StringTokenizer(triggeredComponents, ",", false);
-		String clientId;
-		UIComponent component;
-		boolean handleState = true;
-		// Iterate over the individual client IDs
-		while(st.hasMoreTokens())
-		{
-			clientId = st.nextToken();
-			component = viewRoot.findComponent(clientId);
-			if(component != null)
-			{
-				//get info about state writing/rendering
-				//if at least one ppr does not update the state
-				//the response will not include state information
-				PPRPanelGroup ppr = (PPRPanelGroup) component;
-				if(ppr.getStateUpdate().booleanValue() == false)
-				{
-					handleState = false;
-				}
-				// Write a component tag which contains a CDATA section whith
-				// the rendered HTML
-				// of the component children
-				out.print("<component id=\"" + component.getClientId(context) + "\"><![CDATA[");
-				boolean oldValue = HtmlRendererUtils.isAllowedCdataSection(context);
-				HtmlRendererUtils.allowCdataSection(context, false);
-				try
-				{
-					component.encodeChildren(context);
-				}
-				catch(IOException e)
-				{
-					throw new FacesException(e);
-				}
-				HtmlRendererUtils.allowCdataSection(context, oldValue);
-				out.print("]]></component>");
-			}
-			else
-			{
-				log.debug("PPRPhaseListener component with id" + clientId + "not found!");
-			}
-		}
-
-		if(handleState)
-		{
-			// Write the serialized state into a separate XML element
-			out.print("<state>");
-			FacesContext facesContext = FacesContext.getCurrentInstance();
-			StateManager stateManager = facesContext.getApplication().getStateManager();
-			StateManager.SerializedView serializedView = stateManager.saveSerializedView(facesContext);
-			try
-			{
-				stateManager.writeState(facesContext, serializedView);
-			}
-			catch(IOException e)
-			{
-				throw new FacesException(e);
-			}
-			out.print("</state>");
+public class PPRPhaseListener implements PhaseListener {
+    private static Log log = LogFactory.getLog(PPRPhaseListener.class);
+
+    /**
+     * Request parameter which marks a request as PPR request
+     */
+    private static final String PPR_PARAMETER = "org.apache.myfaces.PPRCtrl.ajaxRequest";
+
+    /**
+     * Request parameter containing a comma separated list of component IDs
+     * of the to be updated components
+     */
+    private static final String TRIGGERED_COMPONENTS_PARAMETER = "org.apache.myfaces.PPRCtrl.triggeredComponents";
+
+    private static final String XML_HEADER = "<?xml version=\"1.0\"?>\n";
+
+    public void afterPhase(PhaseEvent phaseEvent) {
+    }
+
+    /**
+     * Determines wether the currently processed request is a PPR request
+     * (by searching for PPR_PARAMETER in the request parameter map) or an
+     * ordinary HTTP request. If the request is a PPR request the triggered
+     * components are encoded. Otherwise transient components which have
+     * previously been marked not transient by the
+     * {@link PPRPanelGroupRenderer} are set to transient again
+     */
+    public void beforePhase(PhaseEvent event) {
+        if (log.isDebugEnabled()) {
+            log.debug("In PPRPhaseListener beforePhase");
+        }
+
+        final FacesContext context = event.getFacesContext();
+        final ExternalContext externalContext = context.getExternalContext();
+
+        Map requestMap = externalContext.getRequestMap();
+
+        if (isPartialRequest(context)) {
+            processPartialPageRequest(context, externalContext, requestMap);
+        }
+        else {
+            // Iterate over the component tree and set all previously
+            // transient components to transient again
+            resetTransientComponents(context.getViewRoot());
+        }
+    }
+
+    /**
+     * if the provided component was marked transient in the last request
+     * set it to transient. Recursively do the same for all children
+     *
+     * @param comp the component to reset
+     */
+    private void resetTransientComponents(UIComponent comp) {
+        if (comp.getAttributes().containsKey(PPRPanelGroupRenderer.TRANSIENT_MARKER_ATTRIBUTE)) {
+            comp.setTransient(true);
+        }
+        for (Iterator iter = comp.getChildren().iterator(); iter.hasNext();) {
+            UIComponent child = (UIComponent) iter.next();
+            resetTransientComponents(child);
+        }
+    }
+
+    /**
+     * Checks if the currently processed Request is an AJAX request from a
+     * PPRPanelGroup
+     *
+     * @param context the current {@link FacesContext}
+     * @return true if a PPR request is being processed , false otherwise
+     */
+    public static boolean isPartialRequest(FacesContext context) {
+        return context.getExternalContext().getRequestParameterMap().containsKey(PPR_PARAMETER);
+    }
+
+    /**
+     * Respond to an AJAX request from a {@link PPRPanelGroup}. The
+     * triggered components are determined by reading the
+     * TRIGGERED_COMPONENTS_PARAMETER from either the RequestParameterMap or
+     * the Request Map. Those componenets are encoded into an XML response.
+     * The lifecycle is quit afterwards.
+     *
+     * @param context         the current {@link FacesContext}
+     * @param externalContext the current {@link ExternalContext}
+     * @param requestMap      Map containing the request attributes
+     */
+    private void processPartialPageRequest(FacesContext context, final ExternalContext externalContext, Map requestMap) {
+
+        ServletResponse response = (ServletResponse) externalContext.getResponse();
+        ServletRequest request = (ServletRequest) externalContext.getRequest();
+
+        UIViewRoot viewRoot = context.getViewRoot();
+
+        // Set Character encoding, contentType and locale for the response
+        final String characterEncoding = request.getCharacterEncoding();
+        String contentType = getContentType("text/xml", characterEncoding);
+        response.setContentType(contentType);
+        response.setLocale(viewRoot.getLocale());
+
+        // Fetch the comma-separated list of triggered components
+        String triggeredComponents = getTriggeredComponents(context);
+
+        try {
+            PrintWriter out = response.getWriter();
+            context.setResponseWriter(new HtmlResponseWriterImpl(out, contentType, characterEncoding));
+            out.print(XML_HEADER);
+            out.print("<response>\n");
+            encodeTriggeredComponents(out, triggeredComponents, viewRoot, context);
+            out.print("</response>");
+            out.flush();
+        }
+        catch (IOException e) {
+            throw new FacesException(e);
+        }
+
+        context.responseComplete();
+    }
+
+    /**
+     * Fetch the comma-separated list of triggered components. They are
+     * either obtained from the Request Parameter Map where they had
+     * previously been set using
+     * {@link PPRPhaseListener#addTriggeredComponent(FacesContext, String))
+     * or from the request parameter map.
+     *
+     * @param fc the current {@link FacesContext}
+     * @return a comma separated list of component IDs of the components
+     *         which are to be updated
+     */
+    private static String getTriggeredComponents(FacesContext fc) {
+        String triggeredComponents = (String) fc.getExternalContext().getRequestMap().get(TRIGGERED_COMPONENTS_PARAMETER);
+
+        if (triggeredComponents == null) {
+            triggeredComponents = (String) fc.getExternalContext().getRequestParameterMap().get(TRIGGERED_COMPONENTS_PARAMETER);
+        }
+
+        return triggeredComponents;
+    }
+
+    /**
+     * API method for adding triggeredComponents programmatically.
+     *
+     * @param fc                         the current {@link FacesContext}
+     * @param triggeredComponentClientId client ID of the component which is to be updated in
+     *                                   case of a PPR Response
+     */
+    public static void addTriggeredComponent(FacesContext fc, String triggeredComponentClientId) {
+        String triggeredComponents = getTriggeredComponents(fc);
+
+        if (triggeredComponents == null || triggeredComponents.trim().length() == 0) {
+            triggeredComponents = new String();
+        }
+        else {
+            triggeredComponents = triggeredComponents + ",";
+        }
+
+        triggeredComponents = triggeredComponents + triggeredComponentClientId;
+
+        fc.getExternalContext().getRequestMap().put(TRIGGERED_COMPONENTS_PARAMETER, triggeredComponents);
+    }
+
+    /**
+     * Generate content-type String either containing only the mime-type or
+     * mime-type and character enconding.
+     *
+     * @param contentType the contentType/mimeType
+     * @param charset     the character set
+     * @return the content-type String to be used in an HTTP response
+     */
+    private String getContentType(String contentType, String charset) {
+        if (charset == null || charset.trim().length() == 0) {
+            return contentType;
+        }
+        else {
+            return contentType + ";charset=" + charset;
+        }
+    }
+
+    /**
+     * Writes the XML elements for the triggered components to the provided
+     * {@link PrintWriter}. Also encode the current state in a separate XML
+     * element.
+     *
+     * @param out                 the output Writer
+     * @param triggeredComponents comma-separated list of component IDs
+     * @param viewRoot            the current ViewRoot
+     * @param context             the current {@link FacesContext}
+     */
+    private void encodeTriggeredComponents(PrintWriter out, String triggeredComponents, UIViewRoot viewRoot, FacesContext context) {
+        StringTokenizer st = new StringTokenizer(triggeredComponents, ",", false);
+        String clientId;
+        UIComponent component;
+        boolean handleState = true;
+        // Iterate over the individual client IDs
+        while (st.hasMoreTokens()) {
+            clientId = st.nextToken();
+            component = viewRoot.findComponent(clientId);
+            if (component != null) {
+                //get info about state writing/rendering
+                //if at least one ppr does not update the state
+                //the response will not include state information
+                PPRPanelGroup ppr = (PPRPanelGroup) component;
+                if (ppr.getStateUpdate().booleanValue() == false) {
+                    handleState = false;
+                }
+                // Write a component tag which contains a CDATA section whith
+                // the rendered HTML
+                // of the component children
+                out.print("<component id=\"" + component.getClientId(context) + "\"><![CDATA[");
+                boolean oldValue = HtmlRendererUtils.isAllowedCdataSection(context);
+                HtmlRendererUtils.allowCdataSection(context, false);
+                try {
+                    component.encodeChildren(context);
+                }
+                catch (IOException e) {
+                    throw new FacesException(e);
+                }
+                HtmlRendererUtils.allowCdataSection(context, oldValue);
+                out.print("]]></component>");
+            }
+            else {
+                log.debug("PPRPhaseListener component with id" + clientId + "not found!");
+            }
+        }
+
+        if (handleState) {
+            // Write the serialized state into a separate XML element
+            out.print("<state>");
+            FacesContext facesContext = FacesContext.getCurrentInstance();
+            StateManager stateManager = facesContext.getApplication().getStateManager();
+            StateManager.SerializedView serializedView = stateManager.saveSerializedView(facesContext);
+            try {
+                stateManager.writeState(facesContext, serializedView);
+            }
+            catch (IOException e) {
+                throw new FacesException(e);
+            }
+            out.print("</state>");
 		}
 
 	}

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PPRSubmitRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PPRSubmitRenderer.java?rev=641769&r1=641768&r2=641769&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PPRSubmitRenderer.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PPRSubmitRenderer.java Thu Mar 27 03:33:16 2008
@@ -27,9 +27,9 @@
 import javax.faces.context.FacesContext;
 import javax.faces.render.Renderer;
 import java.io.IOException;
-import java.util.List;
-import java.util.Iterator;
 import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
 
 /**
  * @author Thomas Spiegl
@@ -45,8 +45,7 @@
         UIComponent parent = component.getParent();
         if (parent instanceof UICommand) {
             FormInfo fi = RendererUtils.findNestingForm(component, context);
-            if(fi == null)
-            {
+            if (fi == null) {
                 throw new FacesException("PPRPanelGroup must be embedded in a form.");
             }
             PPRSupport.initPPR(context, component);
@@ -63,13 +62,14 @@
                     }
                 }
             }
-        } else {
+        }
+        else {
             // TODO warning
         }
     }
 
     public void addPPRPanelGroupComponents(UIComponent component, List list) {
-        for (Iterator it = component.getChildren().iterator(); it.hasNext(); ) {
+        for (Iterator it = component.getChildren().iterator(); it.hasNext();) {
             UIComponent c = (UIComponent) it.next();
             if (c instanceof PPRPanelGroup) {
                 list.add(c);

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PPRSupport.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PPRSupport.java?rev=641769&r1=641768&r2=641769&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PPRSupport.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PPRSupport.java Thu Mar 27 03:33:16 2008
@@ -18,6 +18,8 @@
  */
 package org.apache.myfaces.custom.ppr;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.myfaces.custom.dojo.DojoConfig;
 import org.apache.myfaces.custom.dojo.DojoUtils;
 import org.apache.myfaces.custom.subform.SubForm;
@@ -25,10 +27,8 @@
 import org.apache.myfaces.renderkit.html.util.AddResourceFactory;
 import org.apache.myfaces.shared_tomahawk.renderkit.JSFAttr;
 import org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils;
-import org.apache.myfaces.shared_tomahawk.renderkit.html.util.FormInfo;
 import org.apache.myfaces.shared_tomahawk.renderkit.html.HTML;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.util.FormInfo;
 
 import javax.faces.FacesException;
 import javax.faces.component.UIComponent;
@@ -36,8 +36,8 @@
 import javax.faces.context.FacesContext;
 import javax.faces.context.ResponseWriter;
 import java.io.IOException;
-import java.util.Map;
 import java.util.List;
+import java.util.Map;
 
 /**
  * @author Ernst Fastl
@@ -74,12 +74,11 @@
      * </ul>
      *
      * @param facesContext the current {@link javax.faces.context.FacesContext}
-     * @param uiComponent	 the currently rendered {@link PPRPanelGroup}
+     * @param uiComponent  the currently rendered {@link PPRPanelGroup}
      * @throws java.io.IOException if the underlying Layer throws an {@link java.io.IOException}
-     *                     it is passed through
+     *                             it is passed through
      */
-    public static void initPPR(FacesContext facesContext, UIComponent uiComponent) throws IOException
-    {
+    public static void initPPR(FacesContext facesContext, UIComponent uiComponent) throws IOException {
         //if(isPartialRequest(facesContext)) {
         //    return;
         //}
@@ -88,15 +87,12 @@
 
         // Do not render the JavaScript if answering to a PPR response
 
-
         //Initialize the client side PPR engine
-        if(!requestMap.containsKey(PPR_INITIALIZED))
-        {
+        if (!requestMap.containsKey(PPR_INITIALIZED)) {
             requestMap.put(PPR_INITIALIZED, Boolean.TRUE);
 
             String encoding = "UTF-8"; // Hardcoded default
-            if(facesContext.getResponseWriter().getCharacterEncoding() != null)
-            {
+            if (facesContext.getResponseWriter().getCharacterEncoding() != null) {
                 encoding = facesContext.getResponseWriter().getCharacterEncoding();
             }
 
@@ -124,12 +120,11 @@
      * </ul>
      *
      * @param facesContext the current {@link FacesContext}
-     * @param pprGroup	 the currently rendered {@link PPRPanelGroup}
+     * @param pprGroup     the currently rendered {@link PPRPanelGroup}
      * @throws IOException if the underlying Layer throws an {@link IOException}
      *                     it is passed through
      */
-    public static void encodeJavaScript(FacesContext facesContext, PPRPanelGroup pprGroup) throws IOException
-    {
+    public static void encodeJavaScript(FacesContext facesContext, PPRPanelGroup pprGroup) throws IOException {
         StringBuffer script = new StringBuffer();
 
         // all JS is put inside a function passed to dojoOnLoad
@@ -179,19 +174,15 @@
                                              PartialTriggerParser.PartialTrigger trigger) {
         String partialTriggerClientId;
         String partialTriggerId = trigger.getPartialTriggerId();
-        if(partialTriggerComponent == null)
-        {
+        if (partialTriggerComponent == null) {
             partialTriggerComponent = facesContext.getViewRoot().findComponent(partialTriggerId);
         }
-        if(partialTriggerComponent != null)
-        {
+        if (partialTriggerComponent != null) {
             partialTriggerClientId = partialTriggerComponent.getClientId(facesContext);
             script.append(pprCtrlReference + "." + ADD_PARTIAL_TRIGGER_FUNCTION + "('" + partialTriggerClientId + "'," + encodeArray(trigger.getEventHooks()) + ",'" + clientId + "');");
         }
-        else
-        {
-            if(log.isDebugEnabled())
-            {
+        else {
+            if (log.isDebugEnabled()) {
                 log.debug("PPRPanelGroupRenderer Component with id " + partialTriggerId + " not found!");
             }
         }
@@ -202,8 +193,7 @@
         UIComponent partialTriggerComponent;
 
         List partialTriggerIds = pprGroup.parsePartialTriggers();
-        for(int i = 0; i < partialTriggerIds.size(); i++)
-        {
+        for (int i = 0; i < partialTriggerIds.size(); i++) {
             PartialTriggerParser.PartialTrigger trigger = (PartialTriggerParser.PartialTrigger) partialTriggerIds
                     .get(i);
             partialTriggerComponent = pprGroup.findComponent(trigger.getPartialTriggerId());
@@ -217,8 +207,7 @@
         String partialTriggerPattern = pprGroup.getPartialTriggerPattern();
 
         //handle partial trigger patterns
-        if(partialTriggerPattern != null && partialTriggerPattern.trim().length() > 0)
-        {
+        if (partialTriggerPattern != null && partialTriggerPattern.trim().length() > 0) {
             script.append(pprCtrlReference + "." + ADD_PARTIAL_TRIGGER_PATTERN_FUNCTION + "('" + partialTriggerPattern + "','" + clientId + "');");
         }
 
@@ -229,8 +218,7 @@
         String inlineLoadingMessage = pprGroup.getInlineLoadingMessage();
 
         //handle inline loading messages
-        if(inlineLoadingMessage != null && inlineLoadingMessage.trim().length() > 0)
-        {
+        if (inlineLoadingMessage != null && inlineLoadingMessage.trim().length() > 0) {
             script.append(pprCtrlReference + "." + ADD_INLINE_LOADING_MESSAGE_FUNCTION + "('" + inlineLoadingMessage + "','" + clientId + "');");
         }
     }
@@ -238,8 +226,7 @@
     private static void encodeSubFormFunction(FacesContext context, PPRPanelGroup pprGroup, StringBuffer script, String pprCtrlReference) {
         String clientId = pprGroup.getClientId(context);
         SubForm subFormParent = findParentSubForm(pprGroup);
-        if(subFormParent != null)
-        {
+        if (subFormParent != null) {
             script.append(pprCtrlReference + "." + SET_SUBFORM_ID_FUNCTION + "('" + subFormParent.getId() + "','" + clientId + "');");
         }
     }
@@ -248,34 +235,30 @@
         String clientId = pprGroup.getClientId(facesContext);
 
         //Handle periodical updates
-        if(pprGroup.getPeriodicalUpdate() != null)
-        {
+        if (pprGroup.getPeriodicalUpdate() != null) {
             List partialTriggers = pprGroup.parsePeriodicalTriggers();
             if (partialTriggers.size() == 0) {
-                Integer wait =  null;
-                if(pprGroup.getExcludeFromStoppingPeriodicalUpdate() != null)
-                {
+                Integer wait = null;
+                if (pprGroup.getExcludeFromStoppingPeriodicalUpdate() != null) {
                     wait = pprGroup.getWaitBeforePeriodicalUpdate();
                 }
                 script.append(pprCtrlReference + ".startPeriodicalUpdate(" + pprGroup.getPeriodicalUpdate() + ",'" + clientId + "', " + wait + ");");
-            } else {
+            }
+            else {
                 String periodicalTriggerId;
                 String periodicalTriggerClientId;
                 UIComponent periodicalTriggerComponent;
-                for(int i = 0; i < partialTriggers.size(); i++)
-                {
+                for (int i = 0; i < partialTriggers.size(); i++) {
                     PartialTriggerParser.PartialTrigger trigger = (PartialTriggerParser.PartialTrigger) partialTriggers
                             .get(i);
                     periodicalTriggerId = trigger.getPartialTriggerId();
                     periodicalTriggerComponent = pprGroup.findComponent(periodicalTriggerId);
-                    if(periodicalTriggerComponent == null)
-                    {
+                    if (periodicalTriggerComponent == null) {
                         periodicalTriggerComponent = facesContext.getViewRoot().findComponent(periodicalTriggerId);
                     }
 
                     // Component found
-                    if(periodicalTriggerComponent != null)
-                    {
+                    if (periodicalTriggerComponent != null) {
                         periodicalTriggerClientId = periodicalTriggerComponent.getClientId(facesContext);
                         script.append(pprCtrlReference + "." + ADD_PERIODICAL_TRIGGER_FUNCTION +
                                 "('" + periodicalTriggerClientId + "'," +
@@ -284,10 +267,8 @@
 
                         // Component missing
                     }
-                    else
-                    {
-                        if(log.isDebugEnabled())
-                        {
+                    else {
+                        if (log.isDebugEnabled()) {
                             log.debug("PPRPanelGroupRenderer Component with id " + periodicalTriggerId + " not found!");
                         }
                     }
@@ -296,8 +277,7 @@
 
             String idRegex = pprGroup.getExcludeFromStoppingPeriodicalUpdate();
 
-            if(idRegex != null)
-            {
+            if (idRegex != null) {
                 script.append(pprCtrlReference + ".excludeFromStoppingPeriodicalUpdate('" + idRegex + "');");
             }
         }
@@ -305,8 +285,7 @@
 
     private static String initPPRFormControl(FacesContext facesContext, PPRPanelGroup pprGroup, StringBuffer script) {
         FormInfo fi = RendererUtils.findNestingForm(pprGroup, facesContext);
-        if(fi == null)
-        {
+        if (fi == null) {
             throw new FacesException("PPRPanelGroup must be embedded in a form.");
         }
         final ExternalContext externalContext = facesContext.getExternalContext();
@@ -316,46 +295,38 @@
         String pprCtrlReference = "dojo.byId('" + formName + "').myFacesPPRCtrl";
 
         //Each form containing PPRPanelGroups has its own PPRCtrl
-        if(!requestMap.containsKey(PPR_INITIALIZED + "." + formName))
-        {
+        if (!requestMap.containsKey(PPR_INITIALIZED + "." + formName)) {
             requestMap.put(PPR_INITIALIZED + "." + formName, Boolean.TRUE);
 
             script.append(pprCtrlReference + "=" + MY_FACES_PPR_INIT_CODE + "('" + formName + "'," + pprGroup.getShowDebugMessages().booleanValue() + "," + pprGroup.getStateUpdate().booleanValue() + ");\n");
 
-            if(pprGroup.getPeriodicalUpdate() != null)
-            {
+            if (pprGroup.getPeriodicalUpdate() != null) {
                 script.append(pprCtrlReference + ".registerOnSubmitInterceptor();");
             }
         }
         return pprCtrlReference;
     }
 
-    public static SubForm findParentSubForm(UIComponent base)
-    {
-        if(base == null) {
+    public static SubForm findParentSubForm(UIComponent base) {
+        if (base == null) {
             return null;
         }
-        if(base instanceof SubForm) {
+        if (base instanceof SubForm) {
             return (SubForm) base;
         }
         return findParentSubForm(base.getParent());
     }
 
-    private static String encodeArray(List eventHooks)
-    {
-        if(eventHooks == null || eventHooks.size() == 0)
-        {
+    private static String encodeArray(List eventHooks) {
+        if (eventHooks == null || eventHooks.size() == 0) {
             return "null";
         }
-        else
-        {
+        else {
             StringBuffer buf = new StringBuffer();
             buf.append("[");
 
-            for(int i = 0; i < eventHooks.size(); i++)
-            {
-                if(i > 0)
-                {
+            for (int i = 0; i < eventHooks.size(); i++) {
+                if (i > 0) {
                     buf.append(",");
                 }
                 String eventHook = (String) eventHooks.get(i);
@@ -374,12 +345,11 @@
      * of the call.
      *
      * @param facesContext The current faces-context.
-     * @param component	The component for which the script is written.
-     * @param script	   The script to be written.
+     * @param component    The component for which the script is written.
+     * @param script       The script to be written.
      * @throws IOException A forwarded exception from the underlying renderer.
      */
-    private static void renderInlineScript(FacesContext facesContext, UIComponent component, String script) throws IOException
-    {
+    private static void renderInlineScript(FacesContext facesContext, UIComponent component, String script) throws IOException {
         ResponseWriter writer = facesContext.getResponseWriter();
         writer.startElement(HTML.SCRIPT_ELEM, component);
         writer.writeAttribute(HTML.TYPE_ATTR, HTML.SCRIPT_TYPE_TEXT_JAVASCRIPT, null);

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PartialTriggerParser.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PartialTriggerParser.java?rev=641769&r1=641768&r2=641769&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PartialTriggerParser.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PartialTriggerParser.java Thu Mar 27 03:33:16 2008
@@ -1,12 +1,12 @@
 package org.apache.myfaces.custom.ppr;
 
-import java.util.List;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.List;
 
 /**
  * @author Martin Marinschek
-*/
+ */
 public class PartialTriggerParser {
 
     public List parse(String partialTriggerString) {
@@ -17,42 +17,43 @@
         List partialTriggers = new ArrayList();
         PartialTrigger currentTrigger = null;
 
-        for(int i=0, length = partialTriggerString.length(); i<=length; i++) {
+        for (int i = 0, length = partialTriggerString.length(); i <= length; i++) {
             boolean newTokenMode = false;
             boolean endTopLevelMode = false;
             boolean endSubLevelMode = false;
 
-            if(!(i==partialTriggerString.length())) {
+            if (!(i == partialTriggerString.length())) {
                 char c = partialTriggerString.charAt(i);
 
-                if(c==',' || c==';' || c==' ') {
+                if (c == ',' || c == ';' || c == ' ') {
                     newTokenMode = true;
                 }
-                else if(c=='(') {
+                else if (c == '(') {
                     newTokenMode = true;
                     subLevelMode = true;
                     endTopLevelMode = true;
                 }
-                else if(c==')') {
+                else if (c == ')') {
                     newTokenMode = true;
                     subLevelMode = false;
                     endSubLevelMode = true;
                 }
-            } else {
+            }
+            else {
                 newTokenMode = true;
             }
 
-            if(newTokenMode) {
-                if(((!subLevelMode && !endSubLevelMode) || endTopLevelMode ) && i>lastTokenEnd) {
+            if (newTokenMode) {
+                if (((!subLevelMode && !endSubLevelMode) || endTopLevelMode) && i > lastTokenEnd) {
                     currentTrigger = new PartialTrigger();
                     partialTriggers.add(currentTrigger);
-                    currentTrigger.setPartialTriggerId(partialTriggerString.substring(lastTokenEnd,i));
+                    currentTrigger.setPartialTriggerId(partialTriggerString.substring(lastTokenEnd, i));
                 }
-                else if((subLevelMode || endSubLevelMode) && i>lastTokenEnd){
-                    currentTrigger.addEventHook(partialTriggerString.substring(lastTokenEnd,i));
+                else if ((subLevelMode || endSubLevelMode) && i > lastTokenEnd) {
+                    currentTrigger.addEventHook(partialTriggerString.substring(lastTokenEnd, i));
                 }
 
-                lastTokenEnd = i+1;
+                lastTokenEnd = i + 1;
             }
         }
 
@@ -65,7 +66,7 @@
         private List eventHooks;
 
         public void addEventHook(String eventHook) {
-            if(eventHooks == null) {
+            if (eventHooks == null) {
                 eventHooks = new ArrayList();
             }
             eventHooks.add(eventHook);
@@ -80,8 +81,9 @@
         }
 
         public List getEventHooks() {
-            if(eventHooks==null)
+            if (eventHooks == null) {
                 return Collections.EMPTY_LIST;
+            }
 
             return eventHooks;
         }