0

I want to set focus to specific component after I go back to my FirstPage..

PageParameters pageParameters = new PageParameters();
setResponsePage(new SecondPage(pageParameters) {
            @Override
            public void doSelect(Integer ID) {                
                setResponsePage(FirstPage.this);
                // set focus to spesific component here

            }

            @Override
            public void doCancel() {
                setResponsePage(FirstPage.this);
            }
        });

Please help me..

Sridhar
  • 1,832
  • 3
  • 23
  • 44
Rendy
  • 11
  • 4

2 Answers2

3

IMO I could choose HTML5 for this . In HTML there's an autofocus attribute to all form fields.

You can decide while page loading which component to be focus.In your case it is the default constructor . Have some criteria and focus on particular component if you are focus the component dynamically otherwise do like below . No Need of Javascript.

TextField textField = new TextField("name");
textField.add(new AttributeModifier("autofocus",""));
soorapadman
  • 4,451
  • 7
  • 35
  • 47
0

You have to add a little JavaScript to your page, search for FocusOnLoadBehavior:

https://cwiki.apache.org/confluence/display/WICKET/Request+Focus+on+a+Specific+Form+Component

svenmeier
  • 5,681
  • 17
  • 22
  • i can't find AbstractBehavior class.. i think we can't using that way because It uses the old wicket version.. – Rendy May 31 '17 at 02:45
  • IIRC they changed it to `Behavior` (which is an `abstract` class). See here :https://ci.apache.org/projects/wicket/apidocs/1.5.x/org/apache/wicket/behavior/AbstractBehavior.html – Rob Audenaerde May 31 '17 at 16:11