Great tip, thanks! After implementing, I see that the behavior is added to the text field correctly, but the renderHead() method is not being called, can you help me understand why that is?
jwcarman wrote: > > On 3/9/08, James Carman <ja...@carmanconsulting.com> wrote: >> On 3/9/08, Warren <war...@clarksnutrition.com> 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: jcar...@carmanconsulting.com >> > > [mailto:jcar...@carmanconsulting.com]on 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: users-unsubscr...@wicket.apache.org >> > > For additional commands, e-mail: users-h...@wicket.apache.org >> > > >> > >> > >> > --------------------------------------------------------------------- >> > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org >> > For additional commands, e-mail: users-h...@wicket.apache.org >> > >> > >> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > > > -- View this message in context: http://old.nabble.com/Default-Focus-Behavior--tp15934889p26944784.html Sent from the Wicket - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org