{"action":"opened","issue":{"url":"https://api.github.com/repos/GwtMaterialDesign/gwt-material-addins/issues/27","repository_url":"https://api.github.com/repos/GwtMaterialDesign/gwt-material-addins","labels_url":"https://api.github.com/repos/GwtMaterialDesign/gwt-material-addins/issues/27/labels{/name}","comments_url":"https://api.github.com/repos/GwtMaterialDesign/gwt-material-addins/issues/27/comments","events_url":"https://api.github.com/repos/GwtMaterialDesign/gwt-material-addins/issues/27/events","html_url":"https://github.com/GwtMaterialDesign/gwt-material-addins/issues/27","id":140799825,"number":27,"title":"MaterialStepper: logic executed at onLoad method can create problems when the component is reattached to the DOM tree.","user":{"login":"gilberto-torrezan","id":7464735,"avatar_url":"https://avatars.githubusercontent.com/u/7464735?v=3","gravatar_id":"","url":"https://api.github.com/users/gilberto-torrezan","html_url":"https://github.com/gilberto-torrezan","followers_url":"https://api.github.com/users/gilberto-torrezan/followers","following_url":"https://api.github.com/users/gilberto-torrezan/following{/other_user}","gists_url":"https://api.github.com/users/gilberto-torrezan/gists{/gist_id}","starred_url":"https://api.github.com/users/gilberto-torrezan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gilberto-torrezan/subscriptions","organizations_url":"https://api.github.com/users/gilberto-torrezan/orgs","repos_url":"https://api.github.com/users/gilberto-torrezan/repos","events_url":"https://api.github.com/users/gilberto-torrezan/events{/privacy}","received_events_url":"https://api.github.com/users/gilberto-torrezan/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-03-14T21:15:26Z","updated_at":"2016-03-14T21:15:26Z","closed_at":null,"body":"The `onLoad()` method of the Widget system is called by the `onAttach()` of the Widget base class, which is turn \"is called when a widget is attached to the browser's document.\" (from the [javadoc](http://www.gwtproject.org/javadoc/latest/com/google/gwt/user/client/ui/Widget.html#onAttach())).\r\n\r\nIn other words, every time the widget is attached to the DOM tree, the `onLoad()` method is called.\r\n\r\nThat becomes a problem when the logic inside the method changes the state of the widget. For instance, on MaterialStepper:\r\n\r\n```java\r\n    @Override\r\n    protected void onLoad() {\r\n        super.onLoad();\r\n        goToStep(1);\r\n    }\r\n```\r\nEvery time the component is reattached, it activates the first step. That's a problem when you have a persistent view where the user can come and go.\r\n\r\nThe MaterialStep have similar problem:\r\n\r\n```java\r\n    @Override\r\n    protected void onLoad() {\r\n        super.onLoad();\r\n        if(getParent() instanceof MaterialStepper){\r\n            stepper = (MaterialStepper) getParent();\r\n            if(stepper.getAxis() == Axis.HORIZONTAL){\r\n                conCircle.add(divTitle);\r\n                conCircle.add(divLine);\r\n                conCircle.add(divDescription);\r\n            }else{\r\n                conBody.insert(divTitle, 0);\r\n                conCircle.add(divLine);\r\n            }\r\n\r\n        }\r\n        conCircle.addClickHandler(new ClickHandler() {\r\n            @Override\r\n            public void onClick(ClickEvent event) {\r\n                stepper.goToStep(step);\r\n            }\r\n        });\r\n    }\r\n```\r\n\r\nIn this case, the layout is redone on every attach, and a click handler is added on every attach. That can lead to multiple click handlers on the component over time."}}