English 中文(简体)
和DataModel的Vaadin。我如何获取标签字段使用的属性DataModel实现存储的值??? Vaadin
原标题:Vaadin and DataModel. How can i get the value stored by a Property DataModel implementation used by a Label Field ??? 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 "数据模型示例";
                }

                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("数据模型示例"));

改为:然而为了了解Property DataModel的内部工作原理,我添加了一个Property实现。但是我并未看到输出。

数据模型示例

我明白了 (wǒ míng bai le)

页: 1

为什么?

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

目 录

最佳回答

我发现为什么

在Property API中,用于以人类可读的文本格式显示其值的方法是toString

以人类可读的文本格式返回该属性的值。

如下所示

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方法告诉您存储在此属性中的类型,没有其他任何内容。它可以是任何东西,甚至是一个账户类。组件本身显示的值始终来自toString方法。

目 录

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签