how to set focus in textbox after responsePage in wicket 7?

908 Views Asked by At

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..

2

There are 2 best solutions below

2
On

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

0
On

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",""));