myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arobinso...@apache.org
Subject svn commit: r918762 - in /myfaces/trinidad/branches/jsf2_ajax: trinidad-examples/trinidad-demo/src/main/webapp/demos/ajaxPPRDemos.xhtml trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Page.js
Date Wed, 03 Mar 2010 23:18:23 GMT
Author: arobinson74
Date: Wed Mar  3 23:18:23 2010
New Revision: 918762

URL: http://svn.apache.org/viewvc?rev=918762&view=rev
Log:
Add focus restoration code to the JSF ajax calls

Modified:
    myfaces/trinidad/branches/jsf2_ajax/trinidad-examples/trinidad-demo/src/main/webapp/demos/ajaxPPRDemos.xhtml
    myfaces/trinidad/branches/jsf2_ajax/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Page.js

Modified: myfaces/trinidad/branches/jsf2_ajax/trinidad-examples/trinidad-demo/src/main/webapp/demos/ajaxPPRDemos.xhtml
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jsf2_ajax/trinidad-examples/trinidad-demo/src/main/webapp/demos/ajaxPPRDemos.xhtml?rev=918762&r1=918761&r2=918762&view=diff
==============================================================================
--- myfaces/trinidad/branches/jsf2_ajax/trinidad-examples/trinidad-demo/src/main/webapp/demos/ajaxPPRDemos.xhtml
(original)
+++ myfaces/trinidad/branches/jsf2_ajax/trinidad-examples/trinidad-demo/src/main/webapp/demos/ajaxPPRDemos.xhtml
Wed Mar  3 23:18:23 2010
@@ -62,6 +62,10 @@
   TrPage.getInstance().getRequestQueue().addStateChangeListener(pprStateChangeFunction);
   TrPage.getInstance().addDomReplaceListener(pprDomReplacementFunction);
 }
+function setFocus(event)
+{
+  event.target.focus();
+}
         </trh:script>
       </tr:group>
     </f:facet>
@@ -196,6 +200,16 @@
                 </tr:panelLabelAndMessage>
               </tr:panelGroupLayout>
             </tr:panelHeader>
+            <tr:panelHeader text="Focus Restoration">
+              <tr:outputFormatted styleUsage="instruction"
+                                  value="The below command button gets the focus on mouse
down and its parent is updated by PPR. It should regain focus after the PPR completes." />
+              <tr:panelGroupLayout id="frpgl1" layout="vertical" partialTriggers="frcb1">
+                <tr:commandButton id="frcb1" text="Demonstrate focus restoration"
+                                  partialSubmit="true">
+                  <trd:invokeFunctionBehavior function="setFocus" event="mousedown" />
+                </tr:commandButton>
+              </tr:panelGroupLayout>
+            </tr:panelHeader>
           </tr:panelGroupLayout>
           <tr:panelLabelAndMessage id="plam1" label="Ajax Status Log">
             <tr:inputText id="it1" value="" simple="true" rows="7" columns="100" />

Modified: myfaces/trinidad/branches/jsf2_ajax/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Page.js
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/jsf2_ajax/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Page.js?rev=918762&r1=918761&r2=918762&view=diff
==============================================================================
--- myfaces/trinidad/branches/jsf2_ajax/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Page.js
(original)
+++ myfaces/trinidad/branches/jsf2_ajax/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Page.js
Wed Mar  3 23:18:23 2010
@@ -63,6 +63,7 @@
   if (params != null)
     source = params.source;
 
+  // TODO: move this to the request queue
   TrPage._delegateToJSFAjax(actionForm, source, event, params);
 
 
@@ -811,14 +812,41 @@
       this._requestQueue._broadcastStateChangeEvent(this._requestQueue._state);
       break;
     case "success":
+      var oldElems = this._ajaxOldDomElements;
       try
       {
-        this._notifyDomReplacementListeners(this._ajaxOldDomElements);
+        this._notifyDomReplacementListeners(oldElems);
       }
       finally
       {
         delete this._ajaxOldDomElements;
       }
+      if (this._activeNode)
+      {
+        var activeNode = this._activeNode;
+        delete this._activeNode;
+        var index = -1;
+        if (activeNode.id)
+        {
+          for (var i = 0, size = oldElems.length; i < size; ++i)
+          {
+            if (TrPage._isDomAncestorOf(activeNode, oldElems[i].element))
+            {
+              index = i;
+              break;
+            }
+          }
+          if (index >= 0)
+          {
+            activeNode = document.getElementById(activeNode.id);
+            window._trActiveElement = activeNode;
+            if (activeNode)
+            {
+              activeNode.focus();
+            }
+          }
+        }
+      }
       this._requestQueue._state = TrRequestQueue.STATE_READY;
       this._requestQueue._broadcastStateChangeEvent(this._requestQueue._state);
       break;
@@ -827,6 +855,7 @@
       // Collect the DOM elements that will be replaced to be able to fire the
       // DOM replacement events
       this._ajaxOldDomElements = this._getDomToBeUpdated(data.responseCode, data.responseXML);
+      this._activeNode = _getActiveElement();
       break;
   }
 }
@@ -838,6 +867,7 @@
   this._requestQueue._state = TrRequestQueue.STATE_READY;
   this._requestQueue._broadcastStateChangeEvent(this._requestQueue._state);
   delete this._ajaxOldDomElements;
+  delete this._activeNode;
 }
 
 TrPage.prototype._notifyDomReplacementListeners = function(dataArray)



Mime
View raw message