Vaadin and DataModel. How can i get the value stored by a Property DataModel implementation used by a Label Field ??? Vaadin
It is just a simple TEST application
import br.com.elf.ui.IndexApplication;
public class IndexApplication extends Application {
public void init() {
setMainWindow(getStartUpWindow());
}
private Window getStartUpWindow() {
Window mainWindow = new Window();
mainWindow.addComponent(
new Label(new Property() {
public Object getValue() {
return "DataModel Example";
}
public void setValue(Object value) throws ReadOnlyException, ConversionException {
throw new ReadOnlyException();
}
public Class<?> getType() {
return String.class;
}
public boolean isReadOnly() {
return true;
}
public void setReadOnly(boolean readyOnly) {
// Empty body
}
));
}
return mainWindow;
}
开发者_如何学Python}
Notice i have i plain Label field. I know i can just call
mainWindow.addComponent(new Label("DataModel Example"));
instead. But in order to see how Property DataModel works behind the scenes, i have added a Property implementation. But instead of seeing in output
DataModel Example
I get
br.com.elf.ui.IndexApplication$1@63a721
Why ???
And what the real purpose of Object getType() method defined in Property interface ??? If HTML shows its output in plain String, so i think there is no reason to implement a Object getType(), do not ???
regards,
I found out why,
The method used to show its value in human-redable textual format is toString. As said in Property API
returns the value of the Property in human readable textual format.
As shown bellow
mainWindow.addComponent(new Label(new Property() {
public Object getValue() {
return "Wellcome to Vaadin!";
}
public void setValue(Object newValue) throws ReadOnlyException, ConversionException {
throw new ReadOnlyException();
}
public Class<?> getType() {
return String.class;
}
public boolean isReadOnly() {
return true;
}
public void setReadOnly(boolean newStatus) {
throw new UnsupportedOperationException();
}
@Override
public String toString() {
return (String) getValue();
}
}));
And getType method tells you the type stored by this Property, nothing else. It can be anything, even a Account class, for instance. The value shown by the Component itself is always derived from toString method.
regards,
精彩评论