jsr372-experts@javaserverfaces-spec-public.java.net

[jsr372-experts] Re: [jsr372-experts mirror] Re: Handling focus after an Ajax update

From: Kito Mann <kito.mann_at_virtua.com>
Date: Mon, 13 Apr 2015 11:00:36 -0400

EB> What needs to change in the spec?


> MM> Remembering the last active element would be a fine solution.

MM> Or, we might introduce something like

MM> <f:ajax execute="..." render="..." focus="elementId"/>


> MM> elementId = someId|_at_this|_at_current


> MM> The focus will be set only, and only if this optional attribute is

MM> provided.


> MM> Such an attribute might offer more flexibility than just the current

MM> element.


> I like the simplicity of this proposal but I think we need to specify a

default behavior. How about we add to the spec that the ajax request

should sample document.activeElement [1] before sending the request and

set the focus to that element after doing the innerHTML replacement?

For the attribute name, I prefer afterFocus. If the afterFocus

attribute is set, the focus must be set to that element after the

innerHTML replacement.


> Ed


The problem with solution is that the focus shouldn't move unless the user
presses the TAB key. At the very least, that should be part of the spec.
Otherwise if you the change event is fired without tab (such as with a
SelectOneMenu or SelectManyCheckbox), the focus would jump that the next
element unexpectedly. Also, one would need to specify previousFocus for
shift-TAB.

I would prefer, however, that the focus control is automatic, based on tab
order. This can be done by retrieving all of the tabbable elements on the
page and determining the one before or after the activeElement. The
automatic focus feature could be turned off by default in web.xml. If we
had this, I'm not sure the explicit functionality would sill be required.

>
> --
> | edward.burns_at_oracle.com | office: +1 407 458 0017
> | 1 days til CONFESS 2015
>
> [1] http://davidwalsh.name/focused-element
>