What about this: Form myForm = new Form("form"); add(myForm); final Component myComponentToFocus = ...; myForm.add(myComponentToFocus);
final ModalWindow modalWindow = new ModalWindow("modal") { @Override public void show(AjaxRequestTarget target) { super.show(target); target.focusComponent(myComponentToFocus); } }; add(modalWindow); modalWindow.setContent(myForm); AjaxLink opener = new AjaxLink("link") { @Override public void onClick(AjaxRequestTarget target) { modalWindow.show(target); } }; add(opener); -Tom > When you have a form in a standard page you can trap the 'onload' event > to set the focus but I couldn't find any useful event to trap when a > form is opened up in a Modal Window - the 'onload' applies to the page > loading, not the ModalWindow (I'm pretty sure). > > The 'least worst' solution I have found is to trap the 'onmouseover' and > set the focus in that, after the focus is set I set a flag to stop it > re-setting the focus every time the mouse re-enters the form. It's still > not perfect but it's a lot better than 'no focus'. I've included the > code below if anyone is interested. > > Is there a better event to be trapping to set the focus? > > class PanelWithAForm extends Panel > { > ... > > protected boolean focusSet = false; > > @Override > protected void onBeforeRender() > { > // Need to reset the focusSet at each re-render > - onInitialize is only called once regardless of how many times the > modal is opened from the hosting page instance > super.onBeforeRender(); > focusSet = false; > } > > protected void onInitialize() > { > super.onInitialize(); > > add(new AjaxEventBehavior("onmouseover") > { > protected void > onEvent(AjaxRequestTarget target) > { > if ( !focusSet ) > { > > target.focusComponent(fieldToFocusOn); > focusSet = > true; > } > } > }); > } > > ... > } --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org