myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ima...@apache.org
Subject svn commit: r642513 - in /myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr: PPRPanelGroup.java PPRPanelGroupRenderer.java PPRPanelGroupTag.java PPRPhaseListener.java PPRSupport.java
Date Sat, 29 Mar 2008 07:22:40 GMT
Author: imario
Date: Sat Mar 29 00:22:33 2008
New Revision: 642513

URL: http://svn.apache.org/viewvc?rev=642513&view=rev
Log:
reformat and optimize import - again

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/PPRSupport.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=642513&r1=642512&r2=642513&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 Sat Mar 29 00:22:33 2008
@@ -18,14 +18,13 @@
  */
 package org.apache.myfaces.custom.ppr;
 
-import javax.faces.context.FacesContext;
-import javax.faces.el.ValueBinding;
-
 import org.apache.myfaces.component.html.ext.HtmlPanelGroup;
 import org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils;
 
-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
@@ -33,257 +32,220 @@
  *
  * @author Ernst Fastl
  */
-public class PPRPanelGroup extends HtmlPanelGroup
-{
-	public static final String COMPONENT_TYPE = "org.apache.myfaces.PPRPanelGroup";
+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 COMPONENT_FAMILY = "org.apache.myfaces.PPRPanelGroup";
 
-	public static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.PPRPanelGroup";
+    public static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.PPRPanelGroup";
 
-	private String _partialTriggers;
+    private String _partialTriggers;
 
-	private Integer _periodicalUpdate;
+    private Integer _periodicalUpdate;
 
-	private String _periodicalTriggers;
+    private String _periodicalTriggers;
 
-	private String _excludeFromStoppingPeriodicalUpdate;
+    private String _excludeFromStoppingPeriodicalUpdate;
 
-	private Integer _waitBeforePeriodicalUpdate = new Integer(2000);
+    private Integer _waitBeforePeriodicalUpdate = new Integer(2000);
 
-	private String _partialTriggerPattern;
+    private String _partialTriggerPattern;
 
-	private String _inlineLoadingMessage;
+    private String _inlineLoadingMessage;
 
-	private Boolean _showDebugMessages = new Boolean(false);
+    private Boolean _showDebugMessages = new Boolean(false);
 
-	private Boolean _stateUpdate = new Boolean(true);
+    private Boolean _stateUpdate = new Boolean(true);
 
     private String _appendMessages;
 
     private String _replaceMessages;
 
-    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 String getAppendMessages()
-	{
-		if(_appendMessages != null)
-		{
-			return _appendMessages;
-		}
-		ValueBinding vb = getValueBinding("appendMessages");
-		return vb != null ? RendererUtils.getStringValue(getFacesContext(), vb) : null;
-	}
-
-	public void setAppendMessages(String appendMessages)
-	{
-		this._appendMessages = appendMessages;
-	}
-
-    public String getReplaceMessages()
-	{
-		if(_replaceMessages != null)
-		{
-			return _replaceMessages;
-		}
-		ValueBinding vb = getValueBinding("replaceMessages");
-		return vb != null ? RendererUtils.getStringValue(getFacesContext(), vb) : null;
-	}
-
-	public void setReplaceMessages(String replaceMessages)
-	{
-		this._replaceMessages = replaceMessages;
-	}
-
-    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];
-		_appendMessages = (String) values[9];
-		_replaceMessages = (String) values[10];
-	}
-
-	public Object saveState(FacesContext context)
-	{
-		Object[] values = new Object[11];
-		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;
-		values[9] = _appendMessages;
-		values[10] = _replaceMessages;
-		return values;
-	}
+    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 String getAppendMessages() {
+        if (_appendMessages != null) {
+            return _appendMessages;
+        }
+        ValueBinding vb = getValueBinding("appendMessages");
+        return vb != null ? RendererUtils.getStringValue(getFacesContext(), vb) : null;
+    }
+
+    public void setAppendMessages(String appendMessages) {
+        this._appendMessages = appendMessages;
+    }
+
+    public String getReplaceMessages() {
+        if (_replaceMessages != null) {
+            return _replaceMessages;
+        }
+        ValueBinding vb = getValueBinding("replaceMessages");
+        return vb != null ? RendererUtils.getStringValue(getFacesContext(), vb) : null;
+    }
+
+    public void setReplaceMessages(String replaceMessages) {
+        this._replaceMessages = replaceMessages;
+    }
+
+    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];
+        _appendMessages = (String) values[9];
+        _replaceMessages = (String) values[10];
+    }
+
+    public Object saveState(FacesContext context) {
+        Object[] values = new Object[11];
+        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;
+        values[9] = _appendMessages;
+        values[10] = _replaceMessages;
+        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;
     }
 
@@ -293,9 +255,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=642513&r1=642512&r2=642513&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 Sat Mar 29 00:22:33 2008
@@ -18,10 +18,10 @@
  */
 package org.apache.myfaces.custom.ppr;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.myfaces.renderkit.html.ext.HtmlGroupRenderer;
 import org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils;
-import org.apache.commons.logging.LogFactory;
-import org.apache.commons.logging.Log;
 
 import javax.faces.component.UIComponent;
 import javax.faces.component.UIViewRoot;
@@ -32,105 +32,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=642513&r1=642512&r2=642513&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 Sat Mar 29 00:22:33 2008
@@ -25,135 +25,117 @@
 /**
  * @author Ernst Fastl
  */
-public class PPRPanelGroupTag extends HtmlPanelGroupTag
-{
-	private String _partialTriggers;
+public class PPRPanelGroupTag extends HtmlPanelGroupTag {
+    private String _partialTriggers;
 
-	private String _partialTriggerPattern;
+    private String _partialTriggerPattern;
 
-	private String _inlineLoadingMessage;
+    private String _inlineLoadingMessage;
 
-	private String _periodicalUpdate;
+    private String _periodicalUpdate;
 
-	private String _periodicalTriggers;
+    private String _periodicalTriggers;
 
-	private String _excludeFromStoppingPeriodicalUpdate;
+    private String _excludeFromStoppingPeriodicalUpdate;
 
-	private String _showDebugMessages;
+    private String _showDebugMessages;
 
-	private String _stateUpdate;
+    private String _stateUpdate;
 
-	private String _waitBeforePeriodicalUpdate;
+    private String _waitBeforePeriodicalUpdate;
 
     private String _appendMessages;
 
     private String _replaceMessages;
 
-    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;
+    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;
         _appendMessages = null;
         _replaceMessages = 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);
-        setStringProperty(component,"appendMessages", _appendMessages);
-        setStringProperty(component,"replaceMessages", _replaceMessages);
-    }
-
-	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;
-	}
+    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);
+        setStringProperty(component, "appendMessages", _appendMessages);
+        setStringProperty(component, "replaceMessages", _replaceMessages);
+    }
+
+    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 String getAppendMessages() {
         return _appendMessages;

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=642513&r1=642512&r2=642513&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 Sat Mar 29 00:22:33 2008
@@ -18,13 +18,19 @@
  */
 package org.apache.myfaces.custom.ppr;
 
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.*;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.component.html.ext.HtmlMessages;
+import org.apache.myfaces.component.html.ext.UIComponentPerspective;
+import org.apache.myfaces.shared_tomahawk.component.ExecuteOnCallback;
+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;
 import javax.faces.application.FacesMessage;
+import javax.faces.application.StateManager;
 import javax.faces.component.UIComponent;
 import javax.faces.component.UIViewRoot;
 import javax.faces.context.ExternalContext;
@@ -36,20 +42,15 @@
 import javax.servlet.ServletResponse;
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.StringTokenizer;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRendererUtils;
-import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlResponseWriterImpl;
-import org.apache.myfaces.shared_tomahawk.component.ExecuteOnCallback;
-import org.apache.myfaces.component.html.ext.HtmlMessages;
-import org.apache.myfaces.component.html.ext.UIComponentPerspective;
-
 /**
  * Before RenderResponse PhaseListener for processing Ajax requests from
  * {@link PPRPanelGroup}. It also participates in handling transient components
@@ -57,316 +58,281 @@
  *
  * @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;
+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;
 
 
         Set toAppendMessagesComponents = new HashSet();
         Set toReplaceMessagesComponents = new HashSet();
 
         // 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
+        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 = null;
                 int oldIndex = 0;
-                if (component instanceof UIComponentPerspective)
-                {
+                if (component instanceof UIComponentPerspective) {
                     UIComponentPerspective uiComponentPerspective = (UIComponentPerspective) component;
-                    ExecuteOnCallback getComponentCallback = new ExecuteOnCallback()
-                    {
+                    ExecuteOnCallback getComponentCallback = new ExecuteOnCallback() {
                         public Object execute(FacesContext context, UIComponent component) {
                             return component;
                         }
                     };
                     Object retval = uiComponentPerspective.executeOn(context, getComponentCallback);
-                    if(retval instanceof PPRPanelGroup)
-                    {
+                    if (retval instanceof PPRPanelGroup) {
                         ppr = (PPRPanelGroup) retval;
-                    } else {
-                         throw new IllegalArgumentException("Expect PPRPanelGroup or UiComponentPerspective");
+                    }
+                    else {
+                        throw new IllegalArgumentException("Expect PPRPanelGroup or UiComponentPerspective");
                     }
                     //setup perspective
                     oldIndex = uiComponentPerspective.getUiData().getRowIndex();
                     uiComponentPerspective.getUiData().setRowIndex(uiComponentPerspective.getRowIndex());
                 }
-                else if( component instanceof PPRPanelGroup)
-                {
+                else if (component instanceof PPRPanelGroup) {
                     ppr = (PPRPanelGroup) component;
-                }  else {
+                }
+                else {
                     throw new IllegalArgumentException("Expect PPRPanelGroup or UiComponentPerspective");
                 }
-                if(ppr.getStateUpdate().booleanValue() == false)
-				{
-					handleState = false;
-				}
+                if (ppr.getStateUpdate().booleanValue() == false) {
+                    handleState = false;
+                }
                 //Check which messages components this group wants to append to
-                if(ppr.getAppendMessages() != null)
-                {
-                    List appendMessagesForThisGroup = getComponentsByCommaSeparatedIdList(context,ppr,ppr.getAppendMessages(), HtmlMessages.class);
+                if (ppr.getAppendMessages() != null) {
+                    List appendMessagesForThisGroup = getComponentsByCommaSeparatedIdList(context, ppr, ppr.getAppendMessages(), HtmlMessages.class);
                     toAppendMessagesComponents.addAll(appendMessagesForThisGroup);
                 }
 
                 //Check which messages components this group should refresh
-                if(ppr.getReplaceMessages() != null)
-                {
-                    List replaceMessagesForThisGroup = getComponentsByCommaSeparatedIdList(context,ppr,ppr.getReplaceMessages(), HtmlMessages.class);
+                if (ppr.getReplaceMessages() != null) {
+                    List replaceMessagesForThisGroup = getComponentsByCommaSeparatedIdList(context, ppr, ppr.getReplaceMessages(), HtmlMessages.class);
                     toReplaceMessagesComponents.addAll(replaceMessagesForThisGroup);
                 }
 
                 // 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>");
+                // 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>");
 
                 //tear down perspective
-                if (component instanceof UIComponentPerspective)
-                {
+                if (component instanceof UIComponentPerspective) {
                     UIComponentPerspective uiComponentPerspective = (UIComponentPerspective) component;
                     uiComponentPerspective.getUiData().setRowIndex(oldIndex);
                 }
             }
-			else
-			{
-				log.debug("PPRPhaseListener component with id" + clientId + "not found!");
-			}
-		}
+            else {
+                log.debug("PPRPhaseListener component with id" + clientId + "not found!");
+            }
+        }
 
         boolean handleFacesMessages = !toAppendMessagesComponents.isEmpty() || !toReplaceMessagesComponents.isEmpty();
 
-        if(handleFacesMessages)
-        {   //encode all facesMessages into  xml-elements
+        if (handleFacesMessages) {   //encode all facesMessages into  xml-elements
             //for starter just return all messages (bother with client IDs later on)
             Iterator messagesIterator = context.getMessages();
 
@@ -380,11 +346,11 @@
             }
 
             //Replace has precedence over append
-            Collection intersection = CollectionUtils.intersection(toAppendMessagesComponents,toReplaceMessagesComponents);
+            Collection intersection = CollectionUtils.intersection(toAppendMessagesComponents, toReplaceMessagesComponents);
             for (Iterator iterator = intersection.iterator(); iterator.hasNext();) {
                 UIComponent uiComponent = (UIComponent) iterator.next();
                 log.warn("Component with id " + uiComponent.getClientId(context) +
-                " is marked for replace and append messages -> replace has precedence");
+                    " is marked for replace and append messages -> replace has precedence");
                 toAppendMessagesComponents.remove(uiComponent);
             }
 
@@ -403,40 +369,38 @@
             }
         }
 
-        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>");
-		}
+        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>");
+        }
 
-	}
+    }
 
     private List getComponentsByCommaSeparatedIdList(FacesContext context, UIComponent comp, String idList, Class desiredType) {
         List retval = new ArrayList();
         UIComponent currentComponent = null;
-        String[] ids = StringUtils.split(idList,',');
+        String[] ids = StringUtils.split(idList, ',');
         for (int i = 0; i < ids.length; i++) {
             String id = StringUtils.trim(ids[i]);
             currentComponent = comp.findComponent(id);
-            if(nullSafeCheckComponentType(desiredType, currentComponent))
-            {
+            if (nullSafeCheckComponentType(desiredType, currentComponent)) {
                 retval.add(currentComponent);
-            } else {
+            }
+            else {
                 currentComponent = context.getViewRoot().findComponent(id);
-                if(nullSafeCheckComponentType(desiredType, currentComponent))
+                if (nullSafeCheckComponentType(desiredType, currentComponent)) {
                     retval.add(currentComponent);
+                }
             }
         }
         return retval;
@@ -446,11 +410,10 @@
         return currentComponent != null && (desiredType == null || desiredType.isAssignableFrom(currentComponent.getClass()));
     }
 
-    private static List getComponentsByCommaSeparatedList(FacesContext context,UIComponent comp, String commaSeparatedIdList, Class componentType)
-    {
+    private static List getComponentsByCommaSeparatedList(FacesContext context, UIComponent comp, String commaSeparatedIdList, Class componentType) {
         List retval = new ArrayList();
         UIComponent currentComponent = null;
-        String[] componentIds =  StringUtils.split(commaSeparatedIdList,',');
+        String[] componentIds = StringUtils.split(commaSeparatedIdList, ',');
         for (int i = 0; i < componentIds.length; i++) {
             String componentId = componentIds[i];
 
@@ -458,8 +421,7 @@
         return retval;
     }
 
-    public PhaseId getPhaseId()
-	{
-		return PhaseId.RENDER_RESPONSE;
-	}
+    public PhaseId getPhaseId() {
+        return PhaseId.RENDER_RESPONSE;
+    }
 }

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=642513&r1=642512&r2=642513&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 Sat Mar 29 00:22:33 2008
@@ -195,7 +195,7 @@
         List partialTriggerIds = pprGroup.parsePartialTriggers();
         for (int i = 0; i < partialTriggerIds.size(); i++) {
             PartialTriggerParser.PartialTrigger trigger = (PartialTriggerParser.PartialTrigger) partialTriggerIds
-                    .get(i);
+                .get(i);
             partialTriggerComponent = pprGroup.findComponent(trigger.getPartialTriggerId());
             encodePartialTrigger(context, script, pprCtrlReference, clientId, partialTriggerComponent, trigger);
         }
@@ -250,7 +250,7 @@
                 UIComponent periodicalTriggerComponent;
                 for (int i = 0; i < partialTriggers.size(); i++) {
                     PartialTriggerParser.PartialTrigger trigger = (PartialTriggerParser.PartialTrigger) partialTriggers
-                            .get(i);
+                        .get(i);
                     periodicalTriggerId = trigger.getPartialTriggerId();
                     periodicalTriggerComponent = pprGroup.findComponent(periodicalTriggerId);
                     if (periodicalTriggerComponent == null) {
@@ -261,9 +261,9 @@
                     if (periodicalTriggerComponent != null) {
                         periodicalTriggerClientId = periodicalTriggerComponent.getClientId(facesContext);
                         script.append(pprCtrlReference + "." + ADD_PERIODICAL_TRIGGER_FUNCTION +
-                                "('" + periodicalTriggerClientId + "'," +
-                                encodeArray(trigger.getEventHooks()) + ",'" + clientId + "', " +
-                                pprGroup.getPeriodicalUpdate() + ");");
+                            "('" + periodicalTriggerClientId + "'," +
+                            encodeArray(trigger.getEventHooks()) + ",'" + clientId + "', " +
+                            pprGroup.getPeriodicalUpdate() + ");");
 
                         // Component missing
                     }



Mime
View raw message