Hi,
answering myself in case it helps someone else in the future.
Inspired by a reply by Josh Canfield to another question in the same
area I came up with the following solution.
I created a PartialMarkupRendererFilter-implementation that takes a
JavaScriptSupport and the field to put focus on:
public class FieldFocusFilter implements PartialMarkupRendererFilter {
private final JavaScriptSupport javaScriptSupport;
private final AbstractField field;
public FieldFocusFilter(final JavaScriptSupport javaScriptSupport,
final AbstractField field) {
this.javaScriptSupport = javaScriptSupport;
this.field = field;
}
@Override
public void renderMarkup(final MarkupWriter writer, final JSONObject reply,
final PartialMarkupRenderer renderer) {
renderer.renderMarkup(writer, reply);
this.javaScriptSupport.autofocus(FieldFocusPriority.OVERRIDE,
this.field.getClientId());
}
}
In my page-class I then inject the PageRenderQueue, JavaScriptSupport
and the field to put focus on:
@Inject
private PageRenderQueue pageRenderQueue;
@Inject
private JavaScriptSupport javaScriptSupport;
@Component
private TextField focusField;
In my onAddRowFromXxx-method I add a new instance of the
FieldFocusFilter to the PageRenderQueue:
this.pageRenderQueue.addPartialMarkupRendererFilter(new
FieldFocusFilter(this.javaScriptSupport, this.focusField));
Thanks for the inspiration Josh. :-)
Regards,
Joakim
On Sat, Feb 26, 2011 at 6:16 PM, Joakim Olsson <[email protected]> wrote:
> Hi,
>
> I would like to get focus on the first available field in the added
> row in an AjaxFormLoop. Is it possible in an easy way?
>
> Regards,
> Joakim
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]