我有一個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 –