0

我有一个选择列表初始化程序,允许用户选择“图像”或“视频”。我需要它 :

  • 如果选择了“视频”类型,则应用 mixinumix:video
  • 如果选择了“图像”类型,则应用 mixinsumix: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:imageandumix:link等的所有属性制作一个 mixin,但我想知道是否有任何选项可以避免这种情况。

谢谢

4

1 回答 1

0

作为一种解决方法,您是否在 cnd 文件中尝试过类似的操作?这个想法是添加一个新的 umix:videoimage 嵌入许多 mixin。也许它会解决你的问题......

[umix:videoMix] mixin
 - video (weakreference, picker[type='video'])  i18n mandatory < jnt:file

[umix:imageMix] mixin
 - image (weakreference, picker[type='image'])  i18n mandatory < jnt:file


[umix:video] > umix:templateMixin,umix:videoMix mixin
 extends = unt:homeHeader

[umix:image] > umix:templateMixin,umix:imageMix mixin
 extends = unt:homeHeader

[umix:videoimage] > umix:templateMixin,umix:videoMix,umix:imageMix mixin
 extends = unt:homeHeader
于 2017-12-28T09:59:55.480 回答