Page 1 of 1

How to add ComboBox to Sdt.

PostPosted: Fri Dec 07, 2012 10:53 pm
by pejfel
Hi.
I tray to use org.docx4j.wml.CTSdtComboBox but I encounter the exception:
[com.sun.istack.internal.SAXException2: unable to marshal type "org.docx4j.wml.CTSdtComboBox" as an element because it is missing an @XmlRootElement annotation]

I know that CTSdtComboBox does not have an @XmlRootElement. Can you tell me how to create ComboBox for docx documents ?
Thanks.

This is my code:

SdtBlock sdt = wmlFactory.createSdtBlock();
org.docx4j.wml.SdtPr sdtPr = wmlFactory.createSdtPr();
sdt.setSdtPr(sdtPr);
org.docx4j.wml.CTSdtComboBox cTSdtComboBox = wmlFactory.createCTSdtComboBox();
CTSdtListItem item = wmlFactory.createCTSdtListItem();
item.setValue("My value");
cTSdtComboBox.getListItem().add(item);

sdtPr.getRPrOrAliasOrLock().add(cTSdtComboBox); // THIS THROWS com.sun.istack.internal.SAXException2

Re: How to add ComboBox to Sdt.

PostPosted: Mon Dec 10, 2012 7:16 pm
by jason
To create a structure like:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
    <w:sdt>
      <w:sdtPr>
        <w:comboBox>
          <w:listItem w:value="Choose an item."/>
          <w:listItem w:displayText="n1" w:value="v1"/>
          <w:listItem w:displayText="n2" w:value="v2"/>
        </w:comboBox>
      </w:sdtPr>
      <w:sdtContent>
        :
      </w:sdtContent>
    </w:sdt>
 
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


please use ObjectFactory's:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
    /**
     * Create an instance of {@link JAXBElement }{@code <}{@link CTSdtComboBox }{@code >}}
     *
     */

    @XmlElementDecl(namespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", name = "comboBox", scope = SdtPr.class)
    public JAXBElement<CTSdtComboBox> createSdtPrComboBox(CTSdtComboBox value) {
        return new JAXBElement<CTSdtComboBox>(_SdtPrComboBox_QNAME, CTSdtComboBox.class, SdtPr.class, value);
    }
 
Parsed in 0.015 seconds, using GeSHi 1.0.8.4


and add JAXBElement<CTSdtComboBox> to the sdtPr object.

In a day or so I'll move this topic to forum data-binding-java-f16/