[opencms-dev] OpenCms 8.5.1 - Add choice field programmatically
Harald Brabenetz
brabenetz at gmx.net
Fri Jun 28 22:18:13 CEST 2013
Hi,
I created a Helper class some times ago.
XmlContentEditorHelper helper = new XmlContentEditorHelper(getCmsObject(), file, locale);
helper.setValue("Content/Text", "TextMessage");
helper.publish();
An example unittest is there:
http://bp-cms-commons.sourceforge.net/m2site/infonova/modules/at.infonova.opencms.modules.commons/1.0/xref-test/at/infonova/opencms/modules/commons/XmlContentEditorHelperTest.html#160
The OpenCms Zip and/or the JAR is in the sourceforge repository:
http://bp-cms-commons.sourceforge.net/m2repo/at/infonova/opencms/modules/at.infonova.opencms.modules.commons/1.0/
You can also copy the sources (it is only one file):
https://sourceforge.net/p/bp-cms-commons/code/1756/tree/opencms_commons/modules/at.infonova.opencms.modules.commons/trunk/src/main/java/at/infonova/opencms/modules/commons/XmlContentEditorHelper.java
I hope it helps.
with friendly regards,
Harald
> Gesendet: Mittwoch, 26. Juni 2013 um 17:41 Uhr
> Von: "Sandrine Prousteau" <s.prousteau at eurelis.com>
> An: "The OpenCms mailing list" <opencms-dev at opencms.org>
> Betreff: [opencms-dev] OpenCms 8.5.1 - Add choice field programmatically
>
> Hi all!!
>
> Does anyone knows how to add an optional choice field to a xmlcontent?
>
> I have a xpath like : Content/Text where Text is a choice field (It could be Image instead for example).
>
> I used
> if(xmlcontent.getValue("Content", locale, 0) == null){
> xmlcontent.addValue(cms, "Content", locale, 0);
> }
> if(xmlcontent.getValue("Content/Text", locale, 0) == null){
> xmlcontent.addValue(cms, "Content/Text", locale, 0);
> }
> But it has a strange behavior, sometimes it creates the field, sometimes it generates an error :
> org.opencms.main.CmsIllegalArgumentException: Unknown XML content element path "Content/Text".
> at org.opencms.xml.content.CmsXmlContent.addValue(CmsXmlContent.java:248)
>
>
> Thanks for your help!
> Sandrine.
>
>
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev
>
>
>
>
More information about the opencms-dev
mailing list