2

I'm using GWT 2.4. I have a reference to a FormPanel, which contains a Button, with id="save." How do I get a reference to the Button widget given the form panel instance?

Note, that Button is not a direct descendant of formPanel, so "formPanel.getWidget()" will not automatically return a reference to the Button.

Thanks, -

Dave
  • 15,639
  • 133
  • 442
  • 830

1 Answers1

-1

You can use

formPanel.getWidget(),

if you're using com.google.gwt.user.client.ui.FormPanel. It will give you the reference to the widget you've added in the FormPanel.

RAS
  • 8,100
  • 16
  • 64
  • 86
  • I'll edit my queston, but the Button with id="save" is not a direct descendant of Formpanel, so getWidget does not return a reference to it. Given this, how do I get a reference to the Button widget given only that I know its id and it is a descendant (at some level) of FormPanel? – Dave Nov 22 '11 at 13:12
  • This answer is actually incorrect. The `getWidget()` method is inherited from `SimplePanel`, which `FormPanel` extends. Calling `getWidget()` would return the one and only widget in the form (the "container" for the form fields). In the case of my example, it would return `fieldContainer`. – Chris Cashwell Nov 22 '11 at 14:50
  • Hey Chris, SimplePanel allows only one widget to be added into it & so does FormPanel according to http://google-web-toolkit.googlecode.com/svn/javadoc/1.6/com/google/gwt/user/client/ui/SimplePanel.html. I've tried running your sample code before posting the answer but I can't get to know that which FormPanel are you using as it gives me `java.lang.IllegalStateException: SimplePanel can only contain one child widget`. Have you run your code before posting it? Or Can you clarify which FormPanel are you using? – RAS Nov 24 '11 at 05:36
  • @RAS You may have missed the edit on November 22. Please try running it again. – Chris Cashwell Nov 28 '11 at 20:24