我有一个Map<String, Boolean>
,我想通过BeanEditor编辑值。如何在Tapestry中为Map创建bean编辑模型?
我一直在关注着,并想我需要创建我自己的财产管道为它:
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"/>
而且我得到的例外是:
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
。
这是要么,否则我提供/调用自定义属性管道失败?
有没有办法解决这个问题,我可以自由编辑地图中的值?
两个链接都不能再工作。我认为这就是为什么提及外部来源对于问题和答案不鼓励的原因。 – MrSmith42
虽然对于感兴趣的代码可以在他的github上找到:https://github.com/uklance/tapestry-stitch –