myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ima...@apache.org
Subject svn commit: r643114 - in /myfaces/tomahawk/trunk/sandbox: core/src/main/java/org/apache/myfaces/custom/ppr/ core/src/main/resources/org/apache/myfaces/custom/ppr/resource/ core/src/main/tld/ examples/src/main/webapp/
Date Mon, 31 Mar 2008 19:36:30 GMT
Author: imario
Date: Mon Mar 31 12:36:28 2008
New Revision: 643114

URL: http://svn.apache.org/viewvc?rev=643114&view=rev
Log:
add componentUpdateFunction which allows one to configure a javascript function which is responsible
for the actual dom update

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/PPRPanelGroupTag.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/ppr/PPRSupport.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/ppr/resource/ppr.js
    myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld
    myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/pprPanelGroupProcessComponents.jsp

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=643114&r1=643113&r2=643114&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
Mon Mar 31 12:36:28 2008
@@ -62,6 +62,8 @@
 
     private String _replaceMessages;
 
+    private String _componentUpdateFunction;
+
     public PPRPanelGroup()
     {
         setRendererType(DEFAULT_RENDERER_TYPE);
@@ -100,6 +102,20 @@
         _periodicalUpdate = periodicalUpdate;
     }
 
+    public String getComponentUpdateFunction()
+    {
+        if (_componentUpdateFunction != null) {
+            return _componentUpdateFunction;
+        }
+        ValueBinding vb = getValueBinding("componentUpdateFunction");
+        return (vb != null) ? (String) vb.getValue(getFacesContext()) : null;
+    }
+
+    public void setComponentUpdateFunction(String componentUpdateFunction)
+    {
+        _componentUpdateFunction = componentUpdateFunction;
+    }
+
     public String getPeriodicalTriggers()
     {
         if (_periodicalTriggers != null) {
@@ -240,11 +256,12 @@
         _waitBeforePeriodicalUpdate = (Integer) values[8];
         _appendMessages = (String) values[9];
         _replaceMessages = (String) values[10];
+        _componentUpdateFunction = (String) values[11];
     }
 
     public Object saveState(FacesContext context)
     {
-        Object[] values = new Object[11];
+        Object[] values = new Object[12];
         values[0] = super.saveState(context);
         values[1] = _partialTriggers;
         values[2] = _partialTriggerPattern;
@@ -256,6 +273,7 @@
         values[8] = _waitBeforePeriodicalUpdate;
         values[9] = _appendMessages;
         values[10] = _replaceMessages;
+        values[11] = _componentUpdateFunction;
         return values;
     }
 

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=643114&r1=643113&r2=643114&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
Mon Mar 31 12:36:28 2008
@@ -49,6 +49,8 @@
 
     private String _replaceMessages;
 
+    private String _componentUpdateFunction;
+
     public String getComponentType()
     {
         return PPRPanelGroup.COMPONENT_TYPE;
@@ -71,6 +73,7 @@
         _waitBeforePeriodicalUpdate = null;
         _appendMessages = null;
         _replaceMessages = null;
+        _componentUpdateFunction = null;
     }
 
     protected void setProperties(UIComponent component)
@@ -88,6 +91,7 @@
         setBooleanProperty(component, "stateUpdate", _stateUpdate);
         setStringProperty(component, "appendMessages", _appendMessages);
         setStringProperty(component, "replaceMessages", _replaceMessages);
+        setStringProperty(component, "componentUpdateFunction", _componentUpdateFunction);
     }
 
     public String getPartialTriggers()
@@ -173,5 +177,15 @@
     public void setReplaceMessages(String _replaceMessages)
     {
         this._replaceMessages = _replaceMessages;
+    }
+
+    public String getComponentUpdateFunction()
+    {
+        return _componentUpdateFunction;
+    }
+
+    public void setComponentUpdateFunction(String componentUpdateFunction)
+    {
+        this._componentUpdateFunction = componentUpdateFunction;
     }
 }

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=643114&r1=643113&r2=643114&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
Mon Mar 31 12:36:28 2008
@@ -61,6 +61,8 @@
 
     private static final String SET_SUBFORM_ID_FUNCTION = "setSubFormId";
 
+    private static final String SET_COMPONENT_UPDATE_FUNCTION = "setComponentUpdateFunction";
+
     private static final String ADD_INLINE_LOADING_MESSAGE_FUNCTION = "addInlineLoadingMessage";
 
     private static final String MY_FACES_PPR_INIT_CODE = "new org.apache.myfaces.PPRCtrl";
@@ -153,6 +155,8 @@
 
         encodeSubFormFunction(facesContext, pprGroup, script, pprCtrlReference);
 
+        encodeDomUpdateConfig(facesContext, pprGroup, script, pprCtrlReference);
+
         encodeInlineLoadMsg(facesContext, pprGroup, script, pprCtrlReference);
 
         encodePartialTriggers(facesContext, pprGroup, script, pprCtrlReference);
@@ -246,6 +250,14 @@
         SubForm subFormParent = findParentSubForm(pprGroup);
         if (subFormParent != null) {
             script.append(pprCtrlReference + "." + SET_SUBFORM_ID_FUNCTION + "('" + subFormParent.getId()
+ "','" + clientId + "');");
+        }
+    }
+
+    private static void encodeDomUpdateConfig(FacesContext context, PPRPanelGroup pprGroup,
StringBuffer script, String pprCtrlReference)
+    {
+        String componentUpdateFunction = pprGroup.getComponentUpdateFunction();
+        if (!StringUtils.isEmpty(componentUpdateFunction)) {
+            script.append(pprCtrlReference + "." + SET_COMPONENT_UPDATE_FUNCTION+ "('" +
componentUpdateFunction + "');");
         }
     }
 

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?rev=643114&r1=643113&r2=643114&view=diff
==============================================================================
--- 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
Mon Mar 31 12:36:28 2008
@@ -31,8 +31,9 @@
 	this.linkIdRegexToExclude = '';
 	this.waitBeforePeriodicalUpdate = null;
 	this.periodicalRegexLinkFound = false;
+    this.componentUpdateFunction = null;
 
-	this.subFormId = new Array();
+    this.subFormId = new Array();
 
 	if(!window.oamPartialTriggersToZoneIds)
 	{
@@ -66,6 +67,14 @@
 	this.reConnectEventHandlers();
 }
 
+// set the component update function to use instead of the default
+// provide a function with the signature:
+// function(formNode, destinationElement, pprResponseElement)
+org.apache.myfaces.PPRCtrl.prototype.setComponentUpdateFunction= function(componentUpdateFunction)
+{
+	this.componentUpdateFunction = componentUpdateFunction;
+};
+
 // set the subform id this ppr belongs to
 org.apache.myfaces.PPRCtrl.prototype.setSubFormId= function(subFormId, refreshZoneId)
 {
@@ -295,9 +304,19 @@
 		  {
   			componentUpdate = componentUpdates[i];
   			domElement = dojo.byId(componentUpdate.getAttribute("id"));
-  			//todo - doesn't work with tables in IE (not used for tables at the moment)
-  			domElement.innerHTML = componentUpdate.firstChild.data;
-  			//parse the new DOM element for script tags and execute them
+            if (this.formNode.myFacesPPRCtrl.componentUpdateFunction != null)
+            {
+                var componentUpdateDom = document.createElement("div");
+                componentUpdateDom.innerHTML = componentUpdate.firstChild.data;
+                
+                eval(this.formNode.myFacesPPRCtrl.componentUpdateFunction)(this.formNode,
domElement, componentUpdateDom);
+            }
+            else
+            {
+                //todo - doesn't work with tables in IE (not used for tables at the moment)
+  			    domElement.innerHTML = componentUpdate.firstChild.data;
+            }
+              //parse the new DOM element for script tags and execute them
   			var regex = /<script([^>]*)>([\s\S]*?)<\/script>/i;
   			var s = domElement.innerHTML;
   			while(match = regex.exec(s)){

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld?rev=643114&r1=643113&r2=643114&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld Mon Mar 31 12:36:28
2008
@@ -1365,6 +1365,14 @@
                 in the page which messages are replaced by this PPRPanelGroup
             </description>
         </attribute>
+        <attribute>
+			<name>componentUpdateFunction</name>
+			<required>false</required>
+			<rtexprvalue>false</rtexprvalue>
+            <description>client javascript function which will do the actual dom update.
function signature:
+                function(formNodeElement, updateTargetElement, pprResponseElement)
+            </description>
+        </attribute>
     </tag>
 
     <tag>

Modified: myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/pprPanelGroupProcessComponents.jsp
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/pprPanelGroupProcessComponents.jsp?rev=643114&r1=643113&r2=643114&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/pprPanelGroupProcessComponents.jsp
(original)
+++ myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/pprPanelGroupProcessComponents.jsp
Mon Mar 31 12:36:28 2008
@@ -72,11 +72,21 @@
             <s:pprPanelGroup id="ppr1"
                              partialTriggers="pprSubmitButtonFail,pprSubmitButtonWork"
                              inlineLoadingMessage="Loading..."
-                             replaceMessages="messages">
-                <h:outputText value="#{pprExampleBean.textField}"/>
+                             replaceMessages="messages"
+                             componentUpdateFunction="localDomUpdateFunction">
+                <h:inputText id="pprOut" value="#{pprExampleBean.textField}" readonly="true"/>
             </s:pprPanelGroup>
         </h:panelGrid>
 
+        <f:verbatim>
+<script type="text/javascript">
+function localDomUpdateFunction(formNode, targetNode, responseNode)
+{
+    document.getElementById("mainform:pprOut").value="LDUF:" + responseNode.firstChild.value;
+}
+</script>
+        </f:verbatim>
+
         <s:fieldset legend="about this example">
             <f:verbatim>
                 <br/>
@@ -90,6 +100,9 @@
                 If you press the first button nothing happens as long as the second textfield
has no data.
                 <br />
                 If you press the second button it is sufficient to enter something into the
first textfield.
+                <br />
+                Also notice that a user defined java script function is used to read the
ppr response and
+                update the dom as required.
             </f:verbatim>
         </s:fieldset>
     </h:form>



Mime
View raw message