I'm trying to get this kind of xml part using docx4j (extract from a word 2007-generated docx):
- Code: Select all
- <w:sdt>
 <w:sdtPr>
 <w:rPr>
 <w:rStyle w:val="input-light" />
 </w:rPr>
 <w:id w:val="200003" />
 <w:lock w:val="sdtLocked" />
 <w:dropDownList>
 <w:listItem w:displayText="Non/applicable" w:value="-1" />
 <w:listItem w:displayText="Yes" w:value="2" />
 <w:listItem w:displayText="No" w:value="3" />
 </w:dropDownList>
 </w:sdtPr>
 <w:sdtContent>
 <w:p w:rsidR="004537C3" w:rsidRDefault="006E7A6A">
 <w:pPr>
 <w:rPr>
 <w:rStyle w:val="input-light" />
 </w:rPr>
 </w:pPr>
 <w:r>
 <w:rPr>
 <w:rStyle w:val="input-light" />
 </w:rPr>
 <w:t>Non/applicable</w:t>
 </w:r>
 </w:p>
 </w:sdtContent>
 </w:sdt>
It all turns out fine, except for the "dropDownList" styling (first <w:rStyle w:val="input-light" /> ). I've tried several methods, including both codes proposed on the doc4j webapp, to create my rPr object and add it to the sdtPr. Example from the webapp :
- Code: Select all
- SdtPr sdtpr = wmlObjectFactory.createSdtPr();
 // Create object for rPr (wrapped in JAXBElement)
 RPr rpr = wmlObjectFactory.createRPr();
 JAXBElement<org.docx4j.wml.RPr> rprWrapped = wmlObjectFactory.createSdtPrRPr(rpr);
 sdtpr.getRPrOrAliasOrLock().add( rprWrapped);
 // Create object for rStyle
 RStyle rstyle = wmlObjectFactory.createRStyle();
 rpr.setRStyle(rstyle);
 rstyle.setVal( "input-light");
But, whatever thr method, when trying to add my sdt object to my MainDocumentPart, I get a java.lang.NullPointerException :
- Code: Select all
- at org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart$FontAndStyleFinder.apply(MainDocumentPart.java:553)
 at org.docx4j.TraversalUtil$CallbackImpl.walkJAXBElements(TraversalUtil.java:163)
 at org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart.addObject(MainDocumentPart.java:702)
If I leave the dropdownList unstyled, it all works fine and my document it created normally.
I might have missed something, since this really doesn't seem to be an expected behavior to me.
Thanks in advance for any ideas on the subject !


 News
 News Site map
 Site map SitemapIndex
 SitemapIndex RSS Feed
 RSS Feed