[opencms-dev] OpenCms 8.5.1 - Add choice field programmatically

Sandrine Prousteau s.prousteau at eurelis.com
Wed Jun 26 17:41:10 CEST 2013


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.





More information about the opencms-dev mailing list