Hi, I have been testing ObjectProperty with TextField. Here is a sample code:
this.floatValue = new Float(1.0f);
mainLayout.addComponent(new TextField("Some value",
new ObjectProperty(this.floatValue)));
After this the text field has the value of the ‘floatValue’. My problem is that if I type new value to the text field it is not propagated to the ‘floatValue’. Maybe I have not understood the ObjectProperty usage, am I?
The value is probagated to the property. (You can not change the value of Float).
Here is working test application to demostrate the behavior:
package fi.jole.test;
import com.itmill.toolkit.Application;
import com.itmill.toolkit.data.util.ObjectProperty;
import com.itmill.toolkit.ui.Button;
import com.itmill.toolkit.ui.TextField;
import com.itmill.toolkit.ui.Window;
import com.itmill.toolkit.ui.Button.ClickEvent;
public class TestApp extends Application {
ObjectProperty property;
public void init() {
Window w = new Window("Test Application");
addWindow(w);
setTheme("corporate");
// Create property
Float floatValue = new Float(1.0f);
property = new ObjectProperty(floatValue);
// Textfield
TextField text = new TextField("Some value", property);
w.addComponent(text);
// Button to change the property
w.addComponent(new Button("increase property value", new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
Float currentValue = (Float) property.getValue();
property.setValue(new Float(currentValue.floatValue() + 1.0));
}}));
// Restart button for appliation
// (easier debugging when you dont have to restart the server to make code changes)
Button restart = new Button("restart", this, "close");
restart.setStyle("link");
w.addComponent(restart);
}
}