Store your widgets in fields and add getter/setter methods so you can
access their data.
Also in your ClickHandler instead of:
((HATestPanel)((Button)
event.getSource()).getParent()).add(compositePanel);
you can simply do
add(compositePanel) or HATextPanel.this.add(compositePanel) if you like.
-- J.
Am Samstag, 14. April 2012 16:17:36 UTC+2 schrieb tong123123:
>
> as shown in the attached image, if I want to access the value of the
> textbox with value "value2" (the textbox in the second row after the "add"
> button"), how to do it as seem there is no a specific name to access it.
>
> the code is as follow:
>
>> package com.mycompany.project.client;
>>
>> import com.google.gwt.event.dom.client.ClickEvent;
>> import com.google.gwt.event.dom.client.ClickHandler;
>> import com.google.gwt.user.client.ui.Button;
>> import com.google.gwt.user.client.ui.FlowPanel;
>> import com.google.gwt.user.client.ui.Widget;
>>
>> public class HATestPanel extends FlowPanel{
>>
>> Button btnAdd = new Button("Add");
>> Button btnListWidget = new Button("List Widget");
>>
>> public void onLoad(){
>>
>> this.add(btnAdd);
>> btnAdd.addClickHandler(new ClickHandler(){
>>
>> @Override
>> public void onClick(ClickEvent event) {
>> // TODO Auto-generated method stub
>> CompositePanel compositePanel = new CompositePanel();
>> ((HATestPanel)((Button)
>> event.getSource()).getParent()).add(compositePanel);
>> }
>>
>> });
>>
>> }
>> }
>>
>
> and the implementation of CompositePanel is as follow:
>
>> package com.mycompany.project.client;
>>
>> import com.google.gwt.user.client.ui.FlowPanel;
>> import com.google.gwt.user.client.ui.HorizontalPanel;
>> import com.google.gwt.user.client.ui.Label;
>> import com.google.gwt.user.client.ui.ListBox;
>> import com.google.gwt.user.client.ui.TextBox;
>>
>> public class CompositePanel extends HorizontalPanel{
>>
>> protected void onLoad(){
>> ListBox lb = new ListBox();
>> TextBox txt2 = new TextBox();
>> lb.addItem("field1");
>> lb.addItem("field2");
>> lb.addItem("field3");
>> this.add(lb);
>> this.add(txt2);
>> }
>>
>> }
>>
>
> maybe my design is poor, any better method suggested?
> in reality, the listbox is used for user select "searc field", and the
> textbox is for user enter search value for that search field.
>
>
>
>
>
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/google-web-toolkit/-/XerPShAubfAJ.
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.