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);
}
});
}}
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);
}}
--
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/-/Rc2QBu_9m6MJ.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
Store them in a separate list or iterate through all child widgets of your HATestPanel using FlowPanel.getWidgetCount() and FlowPanel.getWidget(int index). For each widget check if its a CompositePanel, cast it and call its getter to get the value.
public class HATestPanel extends FlowPanel{
Button btnAdd = new Button("Add");
Button btnListWidget = new Button("submit");
public void onLoad(){
this.add(btnAdd);
this.add(btnListWidget);
btnAdd.addClickHandler(new ClickHandler(){
@Override
public void onClick(ClickEvent event) {
// TODO Auto-generated method stub
CompositePanel compositePanel = new CompositePanel();
HATestPanel.this.add(compositePanel);
}
});
btnListWidget.addClickHandler(new ClickHandler(){
@Override
public void onClick(ClickEvent event) {
// TODO Auto-generated method stub
for (int i=0; i<HATestPanel.this.getWidgetCount();i++){
if (HATestPanel.this.getWidget(i) instanceof CompositePanel){
ListBox lb =((CompositePanel)HATestPanel.this.getWidget(i)).getLb();
TextBox txt = ((CompositePanel)HATestPanel.this.getWidget(i)).getTxt2();
if (lb.getItemText(lb.getSelectedIndex()).equalsIgnoreCase("field1")){
System.out.println(txt.getText());
// validation txt
}else if (lb.getItemText(lb.getSelectedIndex()).equalsIgnoreCase("field2")){
System.out.println(txt.getText());
// validation txt
}
}
}
}
});
}}
But there is still some problem, if I want to add a delete button after each row, is it very difficult?Or the easier method is add a checkbox before the listbox in class CompositePanel and then add a "delete" button (one and only one for the HATestPanel, not per row) to the HATestPanel?