On 3/9/08, Peter Ertl <[EMAIL PROTECTED]> wrote:
> -1 for letting components handle focus. There's only _one_ focus that
>  can set on a page at a time. What if several components demand focus?
>  Who will be the winner?

Well, the last one that requests it will win because it will be the
last javascript statement executed.  The components themselves aren't
requesting focus.  The person who puts the page/form together is
requesting that the component be the one focused.  If they're dumb
enough to try to set focus on more than one form component, then
that's what they'll get.  This isn't for every situation, obviously,
but it could be helpful for many.

>
>  Also, not every WebComponent can receive focus (Label, Image, ...) but
>  only FormComponents (input, select, button, ...)
>

True, I might add some logic into the bind() method to throw an
exception if you pass in a component that can't be focused (a non
FormComponent maybe?).

>  I vote for a method like:
>
>  WebPage#setFocus(FormComponent component)
>
>  class WebPage
>  {
>    private FormComponent focus;
>
>      public final void setFocus(FormComponent component)
>      {
>        focus = component;
>        focus.setOutputMarkupId(true);
>      }
>
>      public void renderHead(IHeaderResponse response)
>      {
>        if (focus != null)
>        {
>         final String item = String.format("document.getElementById('%s')",
>  focus.getMarkupId());
>          final String js = String.format("%s.focus(); try
>  { %s.select() } catch( /* ignore */ )", item);
>
>          response.renderOnDomReadyJavascript(js);
>        }
>      }
>  }
>
>

I still like my way better. ;-)

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to