-
1. Re: blur + rerender +focus=
Nick Belaevski Aug 14, 2009 6:13 PM (in response to Francisco Jose Peredo Noguez)Hello,
So, the problem is how to set focus after AJAX request only if component had focus before, right? -
2. Re: blur + rerender +focus=
Francisco Jose Peredo Noguez Aug 15, 2009 7:15 PM (in response to Francisco Jose Peredo Noguez)Yes, exactly
-
3. Re: blur + rerender +focus=
Francisco Jose Peredo Noguez Aug 15, 2009 8:52 PM (in response to Francisco Jose Peredo Noguez)I guess I could "plug" javascript code (using JQuery selectors) to listen to the focus/blur events of all the form controls and store the id of the last control with focus, and the use the onstop of a4j:status to restore the focus after the ajax call has finished.
But... shouldn't this be the standard behaviour? (shouldnt richfaces, by default, correctly (and transparently) preserve the currently focus control? -
4. Re: blur + rerender +focus=
Francisco Jose Peredo Noguez Aug 16, 2009 11:20 AM (in response to Francisco Jose Peredo Noguez)And so JRF-7706 is created.
-
5. Re: blur + rerender +focus=
Francisco Jose Peredo Noguez Aug 17, 2009 11:48 AM (in response to Francisco Jose Peredo Noguez)Of course, there is a inconvenience with my current workaround: If I have multiple regions, I need to configure each region (or the controls in each region) to use a a4j:status that restores the focus...
Why there are no option to make a4j:status "global" for ALL regions? -
6. Re: blur + rerender +focus=
Francisco Jose Peredo Noguez Aug 17, 2009 11:57 AM (in response to Francisco Jose Peredo Noguez)And this gives birth to feature request RF-7711
-
7. Re: blur + rerender +focus=
Francisco Jose Peredo Noguez Sep 2, 2009 2:06 PM (in response to Francisco Jose Peredo Noguez)One way to avoid the problem of having this "focus preservation" jQuery trick is that if you have multiple regions there is no way to "globally know" if an ajax richfaces call is happening anywhere...
Well, I found one way: using the global queue oncomplete... this makes me able to detect whenever an ajaxcall ends and restore the focus (of course if you have multiple queues then this workaround will not work for you)
Example code:
/layout/template.xhtml (fragment)<!-- header stuff--> <ui:include src="/layout/queueListener.xhtml" /> <!-- Other stuff--> <ui:insert name="body"/> <!-- Other stuff--> <ui:include src="/layout/jQueryTemplate.xhtml" /> <!-- footer stuff-->
/layout/queueListener.xhtml (important fragment)<!-- ui:composition headers--> <script language="javascript" type="text/javascript"> var focusedId; function queueComplete() { jQuery(escapeJQueryId('#'+focusedId)).focus(); } </script> <a:queue oncomplete="queueComplete();" /> <!-- ui:composition closing -->
/layout/jQueryTemplate.xhtml<!-- ui:composition headers--> <a:outputPanel ajaxRendered="true"> <rich:jQuery selector="input" query="focus( function(){ jQuery(this).addClass('focused'); focusedId=jQuery(this).attr('id'); })"/> <rich:jQuery selector="input" query="blur( function(){ jQuery(this).removeClass('focused'); })"/> <rich:jQuery selector="select" query="focus( function(){ jQuery(this).addClass('focused'); focusedId=jQuery(this).attr('id'); })"/> <rich:jQuery selector="select" query="blur( function(){ jQuery(this).removeClass('focused'); })"/> </a:outputPanel> <!-- ui:composition closing -->
That code preserves the focus for all input text and select html elements transparently, as long as you have the global queue enabled (and you do not use other queues anywhere)<context-param> <param-name>org.richfaces.queue.global.enabled</param-name> <param-value>true</param-value> </context-param>
-
8. Re: blur + rerender +focus=
Francisco Jose Peredo Noguez Sep 2, 2009 2:08 PM (in response to Francisco Jose Peredo Noguez)hope this helps anyone with the same problem, and if you see a flaw (or find a better way to do it) please post it here
-
9. Re: blur + rerender +focus=
Francisco Jose Peredo Noguez Sep 2, 2009 2:18 PM (in response to Francisco Jose Peredo Noguez)Oh,I forgot to post the code for the escapeJQueryId function, here it is:
function escapeJQueryId(id) { return id.replace(/:/g,"\\:").replace(/\./g,"\\."); }
And please, if you find this useful, vote for the JIRA issues referenced in previous posts in this same thread -
10. Re: blur + rerender +focus=
Nick Belaevski Sep 2, 2009 2:29 PM (in response to Francisco Jose Peredo Noguez)Note that there are textarea/button/select elements. You can use the following selector:
input, button, select, textarea
. BTW, there is built-in selector: http://docs.jquery.com/Selectors/input.
Also it is possible to add global AJAX listener using A4J.AJAX.addListener() function. -
11. Re: blur + rerender +focus=
Francisco Jose Peredo Noguez Sep 2, 2009 5:25 PM (in response to Francisco Jose Peredo Noguez)"nbelaevski" wrote:
Also it is possible to add global AJAX listener using A4J.AJAX.addListener() function.
Just to be sure I understood correctly, this A4J.AJAX.addListener() works always for all a4j ajax calls regardless of region or queue? (In other words works for all queues for all regions, always no matter what?) -
12. Re: blur + rerender +focus=
Nick Belaevski Sep 2, 2009 5:56 PM (in response to Francisco Jose Peredo Noguez)Yes, listeners added by this method are fired for ALL AJAX request that RF processes.
-
13. Re: blur + rerender +focus=
Francisco Jose Peredo Noguez Sep 3, 2009 12:09 AM (in response to Francisco Jose Peredo Noguez)that... is... really... GREAT
-
14. Re: blur + rerender +focus=
Francisco Jose Peredo Noguez Sep 3, 2009 6:56 PM (in response to Francisco Jose Peredo Noguez)I was happy too soon, if I use limitToList="true" then the oncomplete of the global queue is NOT called!
I wonder if A4J.AJAX.addListener() works with limit to list enabled... (and i wonder why the queue is being affected by the limitToList.... does this mean that ajaxCalls with limitToList="true" skip the global queue?)