Search code examples
javagwtuibinder

gwt dynamic adding textbox


 @UiHandler("addDynamicTextboxbutton")
  void addMoreTextbox(ClickEvent event) {


     textboxplaceholder.add(new TextBox(),"textboxplace");

 }

when addDynamicTextboxbutton button is clicked, this method is executed and new textbox is created. how to have another button, so that when click, will get all the values from each of the "textbox()" ? or is it necessary to put name "new textbox("name")" so that i can get all their values? what is the best practice way to do this?


Solution

  • If textboxplaceholder is and extend of a ComplexPanel, for example FlowPanel you could simply iterate over the children of the FlowPanel:

    for (Widget w: textboxplaceholder) {
       if (w instanceof TextBox) {
         // do something value: ((TextBox)w).getValue();
       }
    }