On Jan 29, 2:20 am, Pion <[email protected]> wrote:
> I have the following code snippets:
>
> VerticalPanel verticalPanel = new VerticalPanel();
>
> Element fieldset = DOM.createFieldSet();
>
> DOM.appendChild(verticalPanel.getElement(), fieldset);
A VerticalPanel's element is a <table>, you really shouldn't add a
<fieldset> as a child of a <table>.
>
> Label label = new Label("Messages");
> label.addClickHandler(new ClickHandler() {
> public void onClick(ClickEvent event) {
> debug("Messages handler");
> }
> }
> );
>
> Based on the above, I have the following 2 options:
>
> // Option 1: When I click "Messages", it calls debug("Messages
> handler").
> // It works as expected.
> verticalPanel.add(label);
>
> // Option 2: When I click "Messages", it did not call debug
> ("Messages handler")
> // It does not work as expected. I expected that it should
> call debug
> ("Messages handler")
> DOM.appendChild(fieldset, label.getElement());
>
> I am using GWT 2.0.
>
> What did I do wrong on option 2? I want the label inside the fieldset.
You have to first understand how events work in GWT:
http://code.google.com/webtoolkit/doc/latest/DevGuideUiCustomWidgets.html#new
http://code.google.com/p/google-web-toolkit/wiki/DomEventsAndMemoryLeaks
http://google-web-toolkit.googlecode.com/svn/javadoc/2.0/com/google/gwt/user/client/ui/Widget.html#doAttachChildren()
But actually, the best documentation is the code itself (have a look
at Widget's onAttach/onDetach and Panel's add/remove methods)
You could also take advantage of event bubbling, which would make your
code much simpler:
http://code.google.com/webtoolkit/doc/latest/FAQ_UI.html#How_can_I_efficiently_handle_events_from_many_interior_Widgets?
Oh, and why not use a CaptionPanel for you <fieldset>?
http://google-web-toolkit.googlecode.com/svn/javadoc/2.0/com/google/gwt/user/client/ui/CaptionPanel.html
Extending CaptionPanel and using event bubbling to detect clicks on
the <legend> (assuming you actually want the label to be the
fieldset's caption) would probably be easier than re-creating a
CaptionPanel-like widget to handle those clicks through a child Label
widget.
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.