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

问题描述 投票:0回答:1

我有一个choicelist initializer,允许用户选择“图像”或“视频”。我需要它 :

  • 如果选择了“视频”类型,请使用mixin umix:video
  • 如果选择了'图像'类型,请使用mixins umix:imageumix: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

home header type list initializer.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等所有属性进行单一混合,但我想知道是否有任何选项可以避免这种情况。

谢谢

java mixins jcr jahia
1个回答
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
© www.soinside.com 2019 - 2024. All rights reserved.