I would rather do some thing like this, to achieve what you are doing. This is based on the assumption that you are trying to read the user entered value on click of a button. There are two option to achieve this.
Option 1
public class MyTextField extends TextField{
public MyTextField(){
}
public String getStr(){
return this.getValue();
}
}
public class MyButton extends Button{
public MyButton(){
setCaption("UPDATE");
}
}
//Add in your presentation logic
final MyTextField text = new MyTextField();
MyButton button = new MyButton();
mainLayout.addComponent(text);
mainLayout.addComponent(button);
button.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
System.out.println(text.getStr());
}
});
Option 2
public class MyTextField extends TextField{
public MyTextField(){
}
public String getStr(){
return this.getValue();
}
}
public class MyButton extends Button{
public MyButton(final MyTextField text){
setCaption("UPDATE");
addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
System.out.println(text.getStr());
}
});
}
}
//And in your presentation logic
final MyTextField text = new MyTextField();
MyButton button = new MyButton(text);
mainLayout.addComponent(text);
mainLayout.addComponent(button);
Please let me know if in case if this is not what you are expecting.
And Kudos to Hovercraft Full Of Eels for trying to help him out
Thanks.