I am using GWT 2.4. In my onModuleLoad method given by the row id, how do I get a link to an existing button on a page from a RootPanel object? I'm trying this
public void onModuleLoad() { ... final Button submitButton = (Button) RootPanel.get("submit");
but getting a compilation error, "Cannot be dropped from RootPanel to Button."
Edit:
I thought using an iterator would heal the pain, but not the cubes. The HTML loaded by default is loaded here (note the button with id = "submit") ...
<div> <form name="f"> File name: <input type="text" size="25" id="filename" name="filename" value="" /> <input type="button" id="submit" name="submit" value="Submit" /> <input type="hidden" name="curId" id="curId" value="" /> </form> </div> <div id="content"></div>
but this code in onModuleLoad raises a NullPointerException (since submitButton id is not found) ...
public void onModuleLoad() { final Button submitButton = (Button) getWidgetById("submit"); submitButton.addStyleName("submitButton"); ... private Widget getWidgetById(final String id) { Widget eltToFind = null; final Iterator<Widget> iter = RootPanel.get().iterator(); while (iter.hasNext()) { final Widget widget = iter.next(); final Element elt = widget.getElement(); if (elt.getId() != null && elt.getId().equals(id)) { eltToFind = widget; break; }
Thanks - Dave
source share