Reputation: 5699
I'm having a Map<String, Boolean>
which I'd like to edit values from via BeanEditor.
I've been poking around and figured I need to create my own property conduit for it:
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;
}
}
I initialized it like this:
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());
}
In my tml
I did this:
<t:beaneditor t:id="mapEditorId" t:object="myMap" t:model="reportingModel"/>
And the exception I get is:
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.
I am kind of puzzled since I was under the impression that I can edit Boolean
s with a simple checkbox.
It's either that, or I failed on providing/calling custom property conduit?
Is there a way to fix this so I can freely edit the values in a map?
Upvotes: 1
Views: 418
Reputation: 27994
There's an example of using a MapPropertyConduit
here
You might also be interested in the map:
binding prefix here
Upvotes: 0
Reputation: 5699
When I changed
this.reportingModel.add(entry.getKey(), new MapPropertyConduit(entry.getKey(), Boolean.class)).dataType(Boolean.class.getName());
to
this.reportingModel.add(entry.getKey(), new MapPropertyConduit(entry.getKey(), Boolean.class)).dataType("boolean");
it suddenly worked.
Does anyone have a complete list of available data types?
Upvotes: 1