java - 如何在Tapestry中为Map创建bean编辑模型?

标签 java properties dictionary edit tapestry

我有一个Map<String, Boolean>我想通过 BeanEditor 编辑值。

我一直在摸索并认为我需要为其创建自己的属性(property)管道:

public class MapPropertyConduit implements PropertyConduit {

    private Object key;
    @SuppressWarnings("rawtypes")
    private Class dataType;

    @SuppressWarnings("rawtypes")
    public MapPropertyConduit(Object key, Class dataType) {
        this.key = key;
        this.dataType = dataType;
    }

    @Override
    public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
        return null;
    }

    @SuppressWarnings("rawtypes")
    @Override
    public Object get(Object instance) {
        return ((Map) instance).get(key);
    }

    @SuppressWarnings("unchecked")
    @Override
    public void set(Object instance, Object value) {
        ((Map) instance).put(key, value);
    }

    @SuppressWarnings("rawtypes")
    @Override
    public Class getPropertyType() {
        return dataType;
    }

}

我这样初始化它:

this.reportingModel = beanModelSource.createEditModel(Map.class, messages);

MViewTransactionDisplayModel selectedModel = getMViewTransactionReportModel();
Map<String, Boolean> displayFields = selectedModel.getDisplayModel();

for (Entry<String, Boolean> entry : displayFields.entrySet()) {
    this.reportingModel.add(entry.getKey(), new MapPropertyConduit(entry.getKey(), Boolean.class)).dataType(Boolean.class.getName());
}

在我的tml我这样做了:

<t:beaneditor t:id="mapEditorId" t:object="myMap" t:model="reportingModel"/>

我得到的异常(exception)是:

Render queue error in BeginRender[MyPage:mapeditorid.propertyeditor]: Unable to locate a block to edit property 'property1' (with data type 'java.lang.Boolean') of object {property1=true, property2=true, property3=true, property4=true, property5=true, property6=true, property7=true, property8=true, property9=true, property10=true, property11=true, property12=true, property13=true}: There is no defined way to edit data of type 'java.lang.Boolean'. Make a contribution to the BeanBlockSource service for this type.

我有点困惑,因为我以为我可以编辑 Boolean带有一个简单的复选框。

是这样,还是我未能提供/调用自定义属性管道?

有没有办法解决这个问题,以便我可以自由编辑 map 中的值?

最佳答案

当我改变

this.reportingModel.add(entry.getKey(), new MapPropertyConduit(entry.getKey(), Boolean.class)).dataType(Boolean.class.getName());

this.reportingModel.add(entry.getKey(), new MapPropertyConduit(entry.getKey(), Boolean.class)).dataType("boolean");

它突然起作用了。

有人有可用数据类型的完整列表吗?

关于java - 如何在Tapestry中为Map创建bean编辑模型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21675856/

相关文章:

ios - Objective C View Controller 属性未保存

java - 获取空结果集以进行简单查询

matlab - 多个属性监听器等待两者触发回调

java - 将 setProperty 传递给内部对象的 setProperty

python - 将值列表追加到字典中

java - 计算房间数量的洪水填充算法

java - HTTP/POST 中的 JMeter 代理和 java 序列化?

java - 如何使用两个表在SQLite数据库中存储多个数据?

java - Spring-hibernate jpa 和 jboss - 将对象保存到第二个数据库

json - React Object of Objects - 如何循环