You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by mm...@apache.org on 2007/07/03 09:37:51 UTC

svn commit: r552700 - in /myfaces/tomahawk/trunk/sandbox: core/src/main/java/org/apache/myfaces/custom/ppr/ core/src/main/resources/org/apache/myfaces/custom/ppr/resource/ examples/src/main/java/org/apache/myfaces/examples/ppr/ examples/src/main/webapp/

Author: mmarinschek
Date: Tue Jul  3 00:37:49 2007
New Revision: 552700

URL: http://svn.apache.org/viewvc?view=rev&rev=552700
Log:
https://issues.apache.org/jira/browse/TOMAHAWK-1043: Adding a PPRPhaseListener.addTriggeredComponent() method to allow manually adding triggered sections on the server

Modified:
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PPRPhaseListener.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/ppr/resource/ppr.js
    myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/ppr/PPRExampleBean.java
    myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/home.jsp
    myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/pprPanelGroupDataTable.jsp
    myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/pprPanelGroupOnChange.jsp

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?view=diff&rev=552700&r1=552699&r2=552700
==============================================================================
--- 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 Tue Jul  3 00:37:49 2007
@@ -60,20 +60,22 @@
 			log.debug("In PPRPhaseListener beforePhase");
 		}
 
-		FacesContext context = event.getFacesContext();
+		final FacesContext context = event.getFacesContext();
 		final ExternalContext externalContext = context.getExternalContext();
 		Map externalRequestMap = externalContext.getRequestParameterMap();
 
-		if (externalRequestMap.containsKey(PPR_PARAMETER)) {
-			processPartialPageRequest(context, externalContext, externalRequestMap);
+        Map requestMap = externalContext.getRequestMap();
+
+        if (externalRequestMap.containsKey(PPR_PARAMETER)) {
+			processPartialPageRequest(context, externalContext, requestMap);
 		}
 	}
 
-	private void processPartialPageRequest(FacesContext context, final ExternalContext externalContext, Map externalRequestMap) {
+	private void processPartialPageRequest(FacesContext context, final ExternalContext externalContext, Map requestMap) {
         //If the PhaseListener is invoked the second time do nothing
-        if(externalContext.getRequestMap().containsKey(PPRPanelGroupRenderer.PPR_RESPONSE))
+        if(requestMap.containsKey(PPRPanelGroupRenderer.PPR_RESPONSE))
             return;
-        externalContext.getRequestMap().put(PPRPanelGroupRenderer.PPR_RESPONSE, Boolean.TRUE);
+        requestMap.put(PPRPanelGroupRenderer.PPR_RESPONSE, Boolean.TRUE);
 
 		ServletResponse response = (ServletResponse) externalContext.getResponse();
 		ServletRequest request = (ServletRequest) externalContext.getRequest();
@@ -83,7 +85,7 @@
 		String contentType = getContentType("text/xml", characterEncoding);
 		response.setContentType(contentType);
 		response.setLocale(viewRoot.getLocale());
-		String triggeredComponents = (String) externalRequestMap.get(TRIGGERED_COMPONENTS_PARAMETER);
+		String triggeredComponents = getTriggeredComponents(context);
 		
 		try {
 			PrintWriter out = response.getWriter();
@@ -100,7 +102,32 @@
 		context.responseComplete();
 	}
 
-	private String getContentType(String contentType, String charset) {
+    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;
+    }
+
+    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);
+    }
+
+    private String getContentType(String contentType, String charset) {
 		if (charset == null || charset.trim().length() == 0)
 			return contentType;
 		else

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/ppr/resource/ppr.js
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/ppr/resource/ppr.js?view=diff&rev=552700&r1=552699&r2=552700
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/ppr/resource/ppr.js (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/ppr/resource/ppr.js Tue Jul  3 00:37:49 2007
@@ -278,16 +278,10 @@
     	}
 
         var triggeredComponents = this.getTriggeredComponents(triggerId);
-        if(triggeredComponents !=null)
-        {
-        	this.displayInlineLoadingMessages(triggeredComponents);
-            content["org.apache.myfaces.PPRCtrl.triggeredComponents"]=triggeredComponents;
-            return this.doAjaxSubmit(content, null, null, event)
-        }
-        else
-        {
-            this.form.submit_orig(triggerElement);
-        }
+        
+        this.displayInlineLoadingMessages(triggeredComponents);
+        content["org.apache.myfaces.PPRCtrl.triggeredComponents"]=triggeredComponents;
+        return this.doAjaxSubmit(content, null, null, event)
     }
     else
     {
@@ -338,7 +332,7 @@
 
 org.apache.myfaces.PPRCtrl.prototype.displayInlineLoadingMessages = function(components)
 {
-	if(typeof components != "string")
+	if(!components)
 	{
 		return;
 	}

Modified: myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/ppr/PPRExampleBean.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/ppr/PPRExampleBean.java?view=diff&rev=552700&r1=552699&r2=552700
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/ppr/PPRExampleBean.java (original)
+++ myfaces/tomahawk/trunk/sandbox/examples/src/main/java/org/apache/myfaces/examples/ppr/PPRExampleBean.java Tue Jul  3 00:37:49 2007
@@ -20,10 +20,13 @@
 package org.apache.myfaces.examples.ppr;
 
 import org.apache.myfaces.examples.inputSuggestAjax.Address;
+import org.apache.myfaces.custom.ppr.PPRPhaseListener;
 
 import javax.faces.FacesException;
+import javax.faces.context.FacesContext;
 import javax.faces.model.SelectItem;
 import javax.faces.component.UIData;
+import javax.faces.component.UIComponent;
 import javax.faces.event.ValueChangeEvent;
 import java.util.ArrayList;
 import java.util.Iterator;
@@ -42,6 +45,8 @@
 
     private String _dropDownValue;
 
+    private String _inputTextValue;
+
     private List _names;
 
     private List _simpleCarList;
@@ -87,6 +92,19 @@
         return _simpleCarList;
     }
 
+    public Integer getSumIds() {
+        List li = getSimpleCarList();
+
+        int sum = 0;
+
+        for (int i = 0; i < li.size(); i++) {
+            SimpleCar simpleCar = (SimpleCar) li.get(i);
+            sum+=simpleCar.getId();
+        }
+
+        return new Integer(sum);
+    }
+
     public void setSimpleCarList(List simpleCarList) {
         _simpleCarList = simpleCarList;
     }
@@ -95,6 +113,24 @@
         Integer id = (Integer) evt.getNewValue();
         SimpleCar car = (SimpleCar) _carTable.getRowData();
         car.setId(id==null?0:id.intValue());
+
+
+        UIData parentUIData = searchParentUIData(evt.getComponent());
+
+        UIComponent comp = parentUIData.findComponent("sum");
+
+        FacesContext fc = FacesContext.getCurrentInstance();
+
+        PPRPhaseListener.addTriggeredComponent(fc,comp.getClientId(fc));
+    }
+
+    private UIData searchParentUIData(UIComponent comp) {
+        if(comp == null)
+            return null;
+        else if(comp.getParent() instanceof UIData)
+            return (UIData) comp.getParent();
+
+        return searchParentUIData(comp.getParent());
     }
 
     public void typeChanged(ValueChangeEvent evt) {
@@ -224,6 +260,15 @@
         _dropDownValue = changeDropDown;
     }
 
+
+    public String getInputTextValue() {
+        return _inputTextValue;
+    }
+
+    public void setInputTextValue(String inputTextValue) {
+        _inputTextValue = inputTextValue;
+    }
+
     public String getMessage() {
         return _message;
     }
@@ -238,6 +283,10 @@
 
     public void dropDownChanged(ValueChangeEvent evt) {
         _dropDownValue = (String) evt.getNewValue();
+    }
+
+    public void inputTextChanged(ValueChangeEvent evt) {
+        _inputTextValue = (String) evt.getNewValue();
     }
 
 }

Modified: myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/home.jsp
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/home.jsp?view=diff&rev=552700&r1=552699&r2=552700
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/home.jsp (original)
+++ myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/home.jsp Tue Jul  3 00:37:49 2007
@@ -37,10 +37,10 @@
 	            <h:outputLink value="pprPanelGroupPartialTriggerPattern.jsf" ><f:verbatim>PPRPanelGroup - update components which ids match a regular expression</f:verbatim></h:outputLink>
 	            <h:outputLink value="pprPanelGroupCommandLink.jsf" ><f:verbatim>PPRPanelGroup - using a command Link for triggering an action via AJAX</f:verbatim></h:outputLink>
 	            <h:outputLink value="pprPanelGroupLoadingMessage.jsf" ><f:verbatim>PPRPanelGroup - displaying an inline Loading Message during AJAX requests</f:verbatim></h:outputLink>
-	            <h:outputLink value="pprPanelGroupOnChange.jsf" ><f:verbatim>PPRPanelGroup - using PPR with drop-down and checkbox onChange handlers</f:verbatim></h:outputLink>
+	            <h:outputLink value="pprPanelGroupOnChange.jsf" ><f:verbatim>PPRPanelGroup - using PPR with input-fields and event handlers (e.g. onclick, onchange, onkeyup)</f:verbatim></h:outputLink>
 	            <h:outputLink value="pprPanelGroupDataScroller.jsf" ><f:verbatim>PPRPanelGroup - ajaxifying a datatable using PPR with partialTriggerPattern</f:verbatim></h:outputLink>
                 <h:outputLink value="pprPanelGroupPeriodicalUpdate.jsf" ><f:verbatim>PPRPanelGroup - parts of a page are getting automatically refreshed by AJAX-Calls (through periodic intervals)</f:verbatim></h:outputLink>
-                <h:outputLink value="pprPanelGroupDataTable.jsf" ><f:verbatim>PPRPanelGroup - parts of a page are getting manually refreshed in a dataTable</f:verbatim></h:outputLink>
+                <h:outputLink value="pprPanelGroupDataTable.jsf" ><f:verbatim>PPRPanelGroup - dataTable example, server-side requested refresh example </f:verbatim></h:outputLink>
             </h:panelGrid>
             <h:outputText value="Resource Serving"/>
             <h:panelGrid style="padding-left:25px">

Modified: myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/pprPanelGroupDataTable.jsp
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/pprPanelGroupDataTable.jsp?view=diff&rev=552700&r1=552699&r2=552700
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/pprPanelGroupDataTable.jsp (original)
+++ myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/pprPanelGroupDataTable.jsp Tue Jul  3 00:37:49 2007
@@ -52,7 +52,7 @@
                 <f:facet name="header">
                     <h:outputText value="Id"/>
                 </f:facet>
-                <h:inputText value="#{carDetail.id}" immediate="true" valueChangeListener="#{pprExampleBean.idChanged}"/>
+                <h:inputText id="id" value="#{carDetail.id}" immediate="true" valueChangeListener="#{pprExampleBean.idChanged}"/>
             </h:column>
             <h:column>
                 <f:facet name="header">
@@ -70,7 +70,7 @@
             </h:column>
             <h:column>
                 <h:commandButton id="update"/>
-                <s:pprPanelGroup id="carEntryUpdate" partialTriggers="update,type(onclick),color(onkeyup)">
+                <s:pprPanelGroup id="carEntryUpdate" partialTriggers="update,id(onkeyup),type(onchange),color(onkeyup)">
                     <h:panelGrid columns="2">
                       <h:outputText value="Id"/>
                       <h:outputText value="#{carDetail.id}"/>
@@ -81,13 +81,23 @@
                     </h:panelGrid>
                 </s:pprPanelGroup>
             </h:column>
+            <f:facet name="footer">
+                <h:panelGroup>
+                    <h:outputText value="Sum of Ids: "/>
+                    <s:pprPanelGroup id="sum">
+                        <h:outputText value="#{pprExampleBean.sumIds}"/>
+                    </s:pprPanelGroup>
+                </h:panelGroup>
+            </f:facet>
         </t:dataTable>
 
         <s:fieldset legend="about this example">
             <f:verbatim>
                  <br />
                  <br />
-                This example demonstrates if and how tables can be used together with the pprPanelGroup.
+                This example demonstrates how tables can be used together with the pprPanelGroup. It also shows
+                (in the table footer) how a component not easily reachable via id-references can be manually
+                added to the list of refreshed components on the server.
             </f:verbatim>
         </s:fieldset>
     </h:form>

Modified: myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/pprPanelGroupOnChange.jsp
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/pprPanelGroupOnChange.jsp?view=diff&rev=552700&r1=552699&r2=552700
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/pprPanelGroupOnChange.jsp (original)
+++ myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/pprPanelGroupOnChange.jsp Tue Jul  3 00:37:49 2007
@@ -50,18 +50,22 @@
 		<h:panelGrid columns="2">
 
 			<h:outputText value="update group by checking:" />
-			<h:selectBooleanCheckbox id="checkbox"
-                    value="#{pprExampleBean.checkBoxValue}" valueChangeListener="#{pprExampleBean.checkBoxChanged}"/>
+			<h:selectBooleanCheckbox id="checkbox" immediate="true"
+                    value="#{pprExampleBean.checkBoxValue}" valueChangeListener="#{pprExampleBean.checkBoxChanged}" required="true"/>
 			
 			<h:outputText value="update group by changing the value:" />
-			<h:selectOneMenu id="dropDown"
-				value="#{pprExampleBean.dropDownValue}"	>
+			<h:selectOneMenu id="dropDown" immediate="true"
+				value="#{pprExampleBean.dropDownValue}"	valueChangeListener="#{pprExampleBean.dropDownChanged}" required="true">
 				<f:selectItem itemLabel="test1" itemValue="value1"/>
 				<f:selectItem itemLabel="test2" itemValue="value2"/>
 				<f:selectItem itemLabel="test3" itemValue="value3"/>
 			</h:selectOneMenu>
-			
-			<h:outputText value="Checkbox is:" />
+
+			<h:outputText value="update group by changing the value:" />
+            <h:inputText id="inputText" immediate="true"
+                         value="#{pprExampleBean.inputTextValue}" valueChangeListener="#{pprExampleBean.inputTextChanged}" required="true"/>
+
+            <h:outputText value="Checkbox is:" />
 			<s:pprPanelGroup id="pprCheckBoxValue"
 				partialTriggers="checkbox(onclick,onchange)">
 				<h:outputText value="#{pprExampleBean.checkBoxValue ? 'checked' : 'not checked'}" />
@@ -72,18 +76,26 @@
 				partialTriggers="dropDown(onchange)">
 				<h:outputText value="#{pprExampleBean.dropDownValue}" />
 			</s:pprPanelGroup>
+
+            <h:outputText value="Input text value is:" />
+			<s:pprPanelGroup id="inputTextPPR"
+				partialTriggers="inputText(onkeyup)">
+				<h:outputText value="#{pprExampleBean.inputTextValue}" />
+			</s:pprPanelGroup>            
         </h:panelGrid>
 
         <s:fieldset legend="about this example">
          <f:verbatim>
              <br />
              <br />
-            This example shows how onClick-Handlers of checkboxes or dropdowns <br />
+            This example shows how event-handlers of input-fields (such as text-inputs, checkboxes or dropdowns) <br />
             can be used to update page regions via AJAX.<br />
-            It is vital, that this element is included as a parameter in the call <br />
-            of the submit function so the PPRCtrl knows which element tries to submit <br />
-            and therefore is able to determine whether or not matching partialTriggers <br />
-            and/or partialTriggerPatterns are present.
+            For this, use the special feature of pprPanelGroup to supply desired-event-handlers in the partialTriggers
+            section of a component. e.g.: componentId1(onkeyup) or componentId2(onclick,onchange).
+            This example also shows that in the general case, you need to set immediate=true and a valueChangeListener
+            on components to make sure that this very component is processed ahead of the pack for conversion
+            and validation, so that a failed conversion or validation won't hinder the AJAXified part of the
+            page to redisplay.
         </f:verbatim>
     </s:fieldset>