gpt4 book ai didi

java - Vaadin 和数据模型。我如何获取标签字段使用的属性数据模型实现存储的值???瓦丁

转载 作者:行者123 更新时间:2023-12-02 08:34:31 26 4
gpt4 key购买 nike

这只是一个简单的测试应用程序

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 实现。但不是在输出中看到

DataModel Example

我明白了

br.com.elf.ui.IndexApplication$1@63a721

为什么???

Property 接口(interface)中定义的 Object getType() 方法的真正目的是什么???如果 HTML 以纯字符串显示其输出,那么我认为没有理由实现 Object getType(),不???

问候,

最佳答案

我找到了原因

用于以人类可读的文本格式显示其值的方法是toString。正如属性 API 中所述

returns the value of the Property in human readable textual format.

如下图

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();
}
}));

getType 方法告诉您此属性存储的类型,仅此而已。它可以是任何东西,例如,甚至是 Account 类。组件本身显示的值始终派生自 toString 方法

问候,

关于java - Vaadin 和数据模型。我如何获取标签字段使用的属性数据模型实现存储的值???瓦丁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2313174/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com