You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by de...@apache.org on 2017/09/17 12:29:37 UTC
[myfaces-trinidad] 07/10: Add focus restoration code to the JSF
ajax calls
This is an automated email from the ASF dual-hosted git repository.
deki pushed a commit to branch jsf2_ajax
in repository https://gitbox.apache.org/repos/asf/myfaces-trinidad.git
commit 4be815fe315b8ab3154b9048885152734c03064b
Author: Andrew Robinson <ar...@apache.org>
AuthorDate: Wed Mar 3 23:18:23 2010 +0000
Add focus restoration code to the JSF ajax calls
---
.../src/main/webapp/demos/ajaxPPRDemos.xhtml | 14 ++++++++++
.../main/javascript/META-INF/adf/jsLibs/Page.js | 32 +++++++++++++++++++++-
2 files changed, 45 insertions(+), 1 deletion(-)
diff --git a/trinidad-examples/trinidad-demo/src/main/webapp/demos/ajaxPPRDemos.xhtml b/trinidad-examples/trinidad-demo/src/main/webapp/demos/ajaxPPRDemos.xhtml
index df31e8f..bfa48e8 100644
--- a/trinidad-examples/trinidad-demo/src/main/webapp/demos/ajaxPPRDemos.xhtml
+++ b/trinidad-examples/trinidad-demo/src/main/webapp/demos/ajaxPPRDemos.xhtml
@@ -62,6 +62,10 @@ function init()
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 @@ function init()
</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" />
diff --git a/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Page.js b/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Page.js
index fcc8288..325f52b 100644
--- a/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Page.js
+++ b/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Page.js
@@ -63,6 +63,7 @@ TrPage.prototype.sendPartialFormPost = function(
if (params != null)
source = params.source;
+ // TODO: move this to the request queue
TrPage._delegateToJSFAjax(actionForm, source, event, params);
@@ -811,14 +812,41 @@ TrPage.prototype._jsfAjaxCallback = function(data)
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 @@ TrPage.prototype._jsfAjaxCallback = function(data)
// 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 @@ TrPage.prototype._jsfAjaxErrorCallback = function(data)
this._requestQueue._state = TrRequestQueue.STATE_READY;
this._requestQueue._broadcastStateChangeEvent(this._requestQueue._state);
delete this._ajaxOldDomElements;
+ delete this._activeNode;
}
TrPage.prototype._notifyDomReplacementListeners = function(dataArray)
--
To stop receiving notification emails like this one, please contact
"commits@myfaces.apache.org" <co...@myfaces.apache.org>.