我有一个选择列表初始化程序,允许用户选择“图像”或“视频”。我需要它 :
- 如果选择了“视频”类型,则应用 mixin
umix:video
- 如果选择了“图像”类型,则应用 mixins
umix:image
和umix:link
可能吗 ?
这是我所拥有的一个最小示例(问题在代码中作为评论):
定义.cnd:
[unt:homeHeader] > jnt:content
- type (string, choicelist[homeHeaderTypeListInitializer,resourceBundle]) = 'image' mandatory autocreated nofulltext
[umix:video] > jmix:templateMixin mixin
extends = unt:homeHeader
- video (weakreference, picker[type='video']) i18n mandatory < jnt:file
[umix:image] > jmix:templateMixin mixin
extends = unt:homeHeader
- image (weakreference, picker[type='image']) i18n mandatory < jnt:file
[umix:link] > jmix:templateMixin mixin
extends = unt:homeHeader
- title (string) i18n < '^.{1,255}$'
- url (string) = 'https://' i18n mandatory indexed=no
homeHeaderTypeListInitializer.java:
public List<ChoiceListValue> getChoiceListValues(ExtendedPropertyDefinition epd, String param, List<ChoiceListValue> values, Locale locale, Map<String, Object> context) {
List<ChoiceListValue> myChoiceList = new ArrayList<>();
if (context == null) {
return myChoiceList;
}
HashMap<String, Object> myPropertiesMap;
myPropertiesMap = new HashMap<>();
myPropertiesMap.put("addMixin", "umix:image");
// HOW CAN I ADD THE SECOND MIXIN umix:link HERE ?
myChoiceList.add(new ChoiceListValue("image", myPropertiesMap, new ValueImpl("image", PropertyType.STRING, false)));
myPropertiesMap = new HashMap<>();
myPropertiesMap.put("addMixin", "umix:video");
myChoiceList.add(new ChoiceListValue("video", myPropertiesMap, new ValueImpl("video", PropertyType.STRING, false)));
return myChoiceList;
}
我知道我可以使用umix:image
andumix:link
等的所有属性制作一个 mixin,但我想知道是否有任何选项可以避免这种情况。
谢谢