tags:

views:

50

answers:

1

I want to access the text elements inside this textbox in GWT from the main method (where I call it like this)

DialogBox aBox =  newCandidatePop.buildNewElecPopup();
    aBox.center();
    aBox.getWidget();

    MiscUiTools.newCandidateHandler(aBox.firstName, aBox.surName);

in newCandidateHandler i want to attach a click handler to the two text boxes

However, the above doesnt quite work - I cant get access to the aBox.firstName elements because they are static methods -- I am wondering what is best practice, how would you code something like this up?

static TextBox firstName = new TextBox();
    static TextBox surName = new TextBox();
    static DialogBox box;

//  public newCandidatePop() {
//      box = buildNewElecPopup();
//  }

    static public DialogBox buildNewElecPopup() {

        DialogBox box = new DialogBox();
        box.setAutoHideEnabled(true);

        box.setText("Add a New Candidate");
        box.setAnimationEnabled(true);
        box.setGlassEnabled(true);

        Grid dialogGrid = new Grid(2, 3);
        dialogGrid.setPixelSize(250 , 125);
        dialogGrid.setCellPadding(10);
        dialogGrid.setWidget(0, 0, new HTML("<strong>First Name</strong>"));
        dialogGrid.setWidget(0, 1, firstName);

        dialogGrid.setWidget(1, 0, new HTML("<strong>Surname</strong>"));
        dialogGrid.setWidget(1, 1, surName);

        box.add(dialogGrid);

    return box;
    }
+1  A: 

Why are the TextBoxes static at all?

public class MyDialogBox extends DialogBox {
  private final TextBox firstName;
  private final TextBox surName;
  public MyDialogBox() {
    firstName = new TextBox();
    surName = new TextBox();

    DialogGrid dialogGrid = new Grid(2, 3);
    // do all your stuff with the grid, add TextBoxes, etc.
    add(dialogGrid);

    setAutoHideEnabled(true);
    // set all the properties of your DialogBox
  }

  public TextBox getFirstNameTextBox() {
    return firstName;
  }
  // same with surName...
} 
Jason Hall
good point - there should'nt be. thanks!
flyingcrab