I extended WebMarkupContainer and called it BodyTag. I would then extend TextField and mark it as needing focus. I would add my TextField to BodyTag and have BodyTag look for a component that needed default focus and then add SimpleAttributeModifier("onload", "document.getElementById('" + component.getMarkupId() + "').focus();") to BodyTag.
Your way looks much cleaner, "java-oriented," especially since I have a lot of other things I add to the "onload" event of the body tag. And the way you have it, it looks like renderHead can get called many times by extending AbstractBehavior. Thanks for the idea, I think I am going to try it your way. I am fairly new to Wicket and am not up to speed on all that it can do and how it does it. I don't know if I answered any of your questions, but you answered a few of mine. Thanks, > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] Behalf Of James Carman > Sent: Sunday, March 09, 2008 8:52 AM > To: users@wicket.apache.org > Subject: Re: Default Focus Behavior? > > > On 3/9/08, James Carman <[EMAIL PROTECTED]> wrote: > > On 3/9/08, Warren <[EMAIL PROTECTED]> wrote: > > > WebMarkupContainer bodyTag = new WebMarkupContainer("bodyTag"); > > > bodyTag.add(new SimpleAttributeModifier("onload", > > > "form.username.focus();")); > > > > > > Ok, but wouldn't it be cooler/easier/more java-oriented to do: > > > > TextField userName = new TextField("userName"); > > userName.addBehavior(new DefaultFocusBehavior()); > > > > or > > > > Behaviors.defaultFocus(userName); // Assuming Behaviors existed. > > > > > > How about something like: > > public class DefaultFocusBehavior extends AbstractBehavior > { > private Component component; > > public void bind( Component component ) > { > this.component = component; > component.setOutputMarkupId(true); > } > > public void renderHead( IHeaderResponse iHeaderResponse ) > { > super.renderHead(iHeaderResponse); > iHeaderResponse.renderOnLoadJavascript("document.getElementById('" > + component.getMarkupId() + "').focus();"); > } > } > > > > > > > > > > > -----Original Message----- > > > > From: [EMAIL PROTECTED] > > > > [mailto:[EMAIL PROTECTED] Behalf Of James Carman > > > > Sent: Sunday, March 09, 2008 7:58 AM > > > > To: users@wicket.apache.org > > > > Subject: Default Focus Behavior? > > > > > > > > > > > > Is there a behavior (or some other way) for having a > field receive the > > > > focus when the page loads? For instance, in a login > form, you'd want > > > > the focus to go to the username field or perhaps the > password field if > > > > you've got "remember me" turned on. > > > > > > > > > > > > --------------------------------------------------------------------- > > > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > > > > > > > > --------------------------------------------------------------------- > > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]