Vaadin 和数据模型。我如何获取标签字段使用的属性数据模型实现存储的值???瓦丁
这只是一个简单的测试应用程序
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;
}
}
注意我有一个简单的标签字段。我知道我可以打电话
mainWindow.addComponent(new Label("DataModel Example"));
代替。但是为了了解 Property DataModel 在幕后如何工作,我添加了一个 Property 实现。但不是在输出中看到
数据模型示例
我得到的
br.com.elf.ui.IndexApplication$1@63a721
为什么???
Property 接口中定义的 Object getType() 方法的真正目的是什么???如果 HTML 以纯字符串显示其输出,那么我认为没有理由实现 Object getType(),不是吗???
问候,
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;
}
}
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,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了原因,
用于以人类可读的文本格式显示其值的方法是toString。正如属性 API 中所述
如下所示
, getType 方法告诉您此属性存储的类型,仅此而已。它可以是任何东西,例如,甚至是 Account 类。组件本身显示的值始终派生自 toString 方法。
问候,
I found out why,
The method used to show its value in human-redable textual format is toString. As said in Property API
As shown bellow
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,