-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?
Also, not every WebComponent can receive focus (Label, Image, ...) but
only FormComponents (input, select, button, ...)
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);
}
}
}
Regards
Peter
Am 09.03.2008 um 20:04 schrieb djo.mos:
jwcarman wrote:
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();");
}
}
This simply looks great ! I think this should make it into the core
Wicket
behaviors as the componenet focus is quite useful.
Cheers.
--
View this message in context:
http://www.nabble.com/Default-Focus-Behavior--tp15934889p15945036.html
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
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]