Hi Michael,

thanks for your help, but it doesn't work yet. My code:

TextField myField = new TextField("text");
myField.setOutputMarkupId(true);
myField.setOutputMarkupPlaceholderTag(true);
add(myField);

   private final class MyLink extends AjaxFallbackLink
   {
public void onClick(AjaxRequestTarget target)
       {
           onShowForm(target);
target.appendJavascript("getElementById('"+myField.getMarkupId()+ "').focus()");
       }
   }

Is there something obviously wrong? Correct Javascript syntax and semantic? Is there an alternative "wicket" approach so that I don't have to use Javascript myself?
Thanks for help
Philipp

use target.(pre|append)Javascript if you want additional JS executed
before/after doing the wicket-ajax stuff

if you only want to set the focus (without any ajax involved), don't use
ajaxlink, use e.g. a simple WebmarkupContainer

hth,
michael


Philipp Daumke-2 wrote:
Dear all,

I try to show and focus on a text field when clicking on a link. The focus however doesn't work. I tried to follow an example in cwiki (http://cwiki.apache.org/WICKET/calling-javascript-function-on-wicket-components-onclick.html) but I somehow do something wrong. I tried to add some javascript attribute via AttributeAppender, but then I get a null pointer exception in onClick ("target is null"). When I comment that line out (so don't add the Attribute), everything works fine except that focus doesn't work.

Any help appreciated.
Thanks a lot
Philipp

Here's my code:

in a WebMarkupContainer:
link.add(new AttributeAppender("onClick", new Model("getElementById('"+textfield.getMarkupId()+ "').onFocus();"), ";"));

in my custom Link Class:
public void onClick(AjaxRequestTarget target)
        {
            showFormThatContainsTextField(target);
 }

void showFormThatContainsTextField(AjaxRequestTarget target)
    {
        // toggle the visibility
         ...
        // redraw the add container.
        target.addComponent(this);
    }

--

Averbis GmbH
c/o Klinikum der Albert-Ludwigs-Universität
Stefan-Meier-Strasse 26
D-79104 Freiburg

Fon: +49 (0) 761 - 203 6707
Fax: +49 (0) 761 - 203 6800
E-Mail: [email protected]

Geschäftsführer: Dr. med. Philipp Daumke, Kornél Markó
Sitz der Gesellschaft: Freiburg i. Br.
AG Freiburg i. Br., HRB 701080


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]





-----
Michael Sparer
http://techblog.molindo.at


--

Averbis GmbH
c/o Klinikum der Albert-Ludwigs-Universität
Stefan-Meier-Strasse 26
D-79104 Freiburg

Fon: +49 (0) 761 - 203 6707
Fax: +49 (0) 761 - 203 6800
E-Mail: [email protected]

Geschäftsführer: Dr. med. Philipp Daumke, Kornél Markó
Sitz der Gesellschaft: Freiburg i. Br.
AG Freiburg i. Br., HRB 701080


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to