M
M
Mikhail Voitenko2013-11-15 15:45:44
Java
Mikhail Voitenko, 2013-11-15 15:45:44

Button handler on GWT?

Essence: there is a widget (panel). It has a button on it. When I click on a button, I want to remove the current widget entirely and go to another one.
Now I have a button

Button editBtn = new Button("Edit user",new editHandler(this));

and a separate class for this button handler
private class editHandler implements ClickHandler {
        private Widget panel;
        editHandler(Widget panel) {
            this.panel = panel;
        }
        public void onClick(ClickEvent event) {
            isUserEditing = true;
            RootPanel.get().remove(panel);
            RootPanel.get().remove(panel);
            RootPanel.get().add(new UserForm(resTab.selectedUser));
        }
    }

As you can see - the implementation is very clumsy - the handler constructor takes a widget, assigns it to another, and only then deletes it.
How can I write a handler right next to the button creation so that it looks like
Button addUserBtn = new Button("Add user", new ClickHandler(this) {
            .......
        });

because I'm having trouble passing the current widget to the handler's constructor.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SergeyGrigorev, 2013-11-15
@Firehanded

You will not be able to pass a button inside a handler like this.
Simply because ClickHandler will be created first (because it is a calculated value) and only then its instance will be passed to the Button constructor. By the time ClickHandler is created, your button constructor has not yet been called and there is no reference to it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question