Thanks, guys.

I think I was over-thinking this. I've decided to do this with pure
Javascript included on every page, just giving focus to the first
non-disabled input element. Igor's comment about metadata made me realize
I was already tagging invalid fields with "invalid" in the class
attribute, so I keyed off that to give those fields priority. I also use
the CSS class name "nofocus" to avoid always giving focus to a search
input at the top of each page.

I've attached the JS if anyone's interested. It won't give focus to a
select or textarea, but I don't need that just now.

jk


On Tue, April 3, 2007 2:04 am, Peter Thomas said:
> You may already know the quick un-generic way to do this - but for example
> this is what I have on a login page where I set focus to the password
> field
> in case the user-id field is already filled in.
>
> getBodyContainer().addOnLoadModifier(new AbstractReadOnlyModel() {
>     public Object getObject() {
>         String markupId;
>         if(loginName.getConvertedInput() == null) {
>             markupId = loginName.getMarkupId();
>         } else {
>             markupId = password.getMarkupId();
>         }
>         return "document.getElementById('" + markupId + "').focus()";
>     }
> }, password);
>
>
> On 4/3/07, Igor Vaynberg <[EMAIL PROTECTED]> wrote:
>>
>> you can set some metadata into these components. have your page/form
>> subclass implement iheaderresponse, traverse the hierararchy in
>> renderhead
>> and set focus to the first component with the right metadata through the
>> header response that is passed in.
>>
>> sounds like a mouthful, but should be pretty simple to implement.
>>
>> -igor
>>
>>
>> On 4/2/07, John Krasnay < [EMAIL PROTECTED]> wrote:
>> >
>> > Hi folks,
>> >
>> > I'm new to Wicket and I'm wondering if there's a "Wicket way" to have
>> > input focus set to the first form component on the page. I could
>> always
>> > code up some
>> > Javascript to do this but it would be nice if I could flag certain
>> form
>> > components as "wanting focus", then have the page set the focus to the
>> > first of these. Ideally, if any form components had failed validation,
>> > the
>> > page would ignore the "wanting focus" flag and give focus to the first
>> > invalid field.
>> >
>> > Any ideas?
>> >
>> > jk
>> >
>> >
>> >
>> >
>> > -------------------------------------------------------------------------
>> > Take Surveys. Earn Cash. Influence the Future of IT
>> > Join SourceForge.net's Techsay panel and you'll get the chance to
>> share
>> > your
>> > opinions on IT & business topics through brief surveys-and earn cash
>> >
>> > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
>> > _______________________________________________
>> > Wicket-user mailing list
>> > Wicket-user@lists.sourceforge.net
>> > https://lists.sourceforge.net/lists/listinfo/wicket-user
>> >
>>
>>
>> -------------------------------------------------------------------------
>> Take Surveys. Earn Cash. Influence the Future of IT
>> Join SourceForge.net's Techsay panel and you'll get the chance to share
>> your
>> opinions on IT & business topics through brief surveys-and earn cash
>> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
>> _______________________________________________
>> Wicket-user mailing list
>> Wicket-user@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/wicket-user
>>
>>
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share
> your
> opinions on IT & business topics through brief surveys-and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV_______________________________________________
> Wicket-user mailing list
> Wicket-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/wicket-user
>

Attachment: focus.js
Description: JavaScript source

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to