Jahia:在一个选择列表初始化器中添加2个mixin?

时间:2017-11-03 10:15:17

标签: java mixins jcr jahia

我有一个choicelist initializer,允许用户选择' image'或者'视频'。我需要那个:

  • 如果'视频'选择了类型,应用mixin umix:video
  • 如果'图片'选择了类型,应用mixins umix:image umix:link

有可能吗?

以下是我所拥有的最小示例(问题在代码中作为注释):

definitions.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:imageumix:link等所有属性制作单个mixin,但我想知道是否有任何选项可以避免这种情况。

由于

1 个答案:

答案 0 :(得分:0)

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

[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