Page 1 of 1

Filling out a template - nested repeats

PostPosted: Sat Sep 11, 2010 3:55 am
by dcole
So I was able to get your invoice demo up and working, as well as one of my own. There was one small hitch I had - how did you put the repeat content control on the table? I tried a couple of different ways, and couldnt get it with my own table - ended up copying yours and modifying it in my own document to get it working.

Did you draw the table first, put cursor in the row, select to the end of the row, then choose the content control? Then drag the other CC's into the interior of the Repeat CC?

I tried making a one row table and selecting it, and then putting the CC around it that way - never could get it working. When I ran my code, it would only put in the first entry from my custom XML, not any of the repeats.


Second question, and probably most important. If I am doing this for a resume, and I have a list of employers for an employee, I was able to to get it to loop over the previous Employers and insert them into my document (using a table, i just turned off borders, it turned out nicely!). Then I thought I would be able to embed another table in my Employers table, and pull the same trick, where in XML i have something like this
<employers>
<employer>
<employerName>Some place</employerName>
<projects>
<project>
<projectName>1st project</projectName>
</project>
<project>
<projectName>2nd Project</projectName>
</project>
</projects>
</employer>
</employers>

So in other words I want it to grab the first employer, then repeat over all those projects that the person had in there for that employer.

I tried to set my binding up on that embedded table like so:
bindingrole=repeat&w:xpath=/resume[1]/employers[1]/projects&w:storeItemID={72FAEA80-BBA1-4063-876F-B1CEAAF6FD6C}

But I get a NPE in the code when it gets to this line: customXmlDataStoragePart.preprocess(wordMLPackage);

Is my tag set up wrong, or is this just not a feature yet?

Re: Filling out a template with Strings of data

PostPosted: Tue Sep 14, 2010 12:04 am
by dcole
bump..any tips?

Re: Filling out a template with Strings of data

PostPosted: Tue Sep 14, 2010 2:41 am
by jason
dcole wrote:So I was able to get your invoice demo up and working, as well as one of my own. There was one small hitch I had - how did you put the repeat content control on the table? I tried a couple of different ways, and couldnt get it with my own table - ended up copying yours and modifying it in my own document to get it working.

Did you draw the table first, put cursor in the row, select to the end of the row, then choose the content control? Then drag the other CC's into the interior of the Repeat CC?

I tried making a one row table and selecting it, and then putting the CC around it that way - never could get it working. When I ran my code, it would only put in the first entry from my custom XML, not any of the repeats.


You can put a content control around a row by selecting the row, and clicking on the rich text content control in the Developer tab.

Putting content controls in cells, well, sometimes they seem to surround a cell. (Going by the document I just created. So I modified the XML manually).

dcole wrote:Second question, and probably most important. If I am doing this for a resume, and I have a list of employers for an employee, I was able to to get it to loop over the previous Employers and insert them into my document (using a table, i just turned off borders, it turned out nicely!). Then I thought I would be able to embed another table in my Employers table, and pull the same trick, where in XML i have something like this
<employers>
<employer>
<employerName>Some place</employerName>
<projects>
<project>
<projectName>1st project</projectName>
</project>
<project>
<projectName>2nd Project</projectName>
</project>
</projects>
</employer>
</employers>

So in other words I want it to grab the first employer, then repeat over all those projects that the person had in there for that employer.

I tried to set my binding up on that embedded table like so:
bindingrole=repeat&w:xpath=/resume[1]/employers[1]/projects&w:storeItemID={72FAEA80-BBA1-4063-876F-B1CEAAF6FD6C}

But I get a NPE in the code when it gets to this line: customXmlDataStoragePart.preprocess(wordMLPackage);

Is my tag set up wrong, or is this just not a feature yet?


That was a TODO, until today :-)

You've prompted me to support this, which meant re-writing the impementation: http://dev.plutext.org/trac/docx4j/changeset/1223

The code stills needs to be tidied up, but the pre-processing works on my new example document: http://dev.plutext.org/trac/docx4j/changeset/1224

You can try it now if you build from svn trunk tip; otherwise, I'll make a nightly tomorrow.

Re: Filling out a template - nested repeats

PostPosted: Wed Sep 15, 2010 1:25 am
by dcole
There seems to be a couple of bugs with the 9/14 nightly build of this.

I havent had any problems using my template thus far with your previous build, however, when using this build, I get the following:

javax.xml.bind.MarshalException
- with linked exception:
[com.sun.istack.SAXException2: unable to marshal type "org.docx4j.wml.Pict" as an element because it is missing an @XmlRootElement annotation]
at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:318)
at com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:244)
at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:110)
at org.docx4j.XmlUtils.marshaltoW3CDomDocument(XmlUtils.java:496)
at org.docx4j.XmlUtils.marshaltoW3CDomDocument(XmlUtils.java:478)
at org.docx4j.openpackaging.parts.CustomXmlDataStoragePart.applyBindings(CustomXmlDataStoragePart.java:776)
at CustomXmlBinding.main(CustomXmlBinding.java:229)
Caused by: com.sun.istack.SAXException2: unable to marshal type "org.docx4j.wml.Pict" as an element because it is missing an @XmlRootElement annotation
at com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:248)
at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:320)
at com.sun.xml.bind.v2.runtime.property.ArrayReferenceNodeProperty.serializeListBody(ArrayReferenceNodeProperty.java:114)
at com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERProperty.java:155)
at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:340)
at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsSoleContent(XMLSerializer.java:593)
at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:324)
at com.sun.xml.bind.v2.runtime.property.ArrayReferenceNodeProperty.serializeListBody(ArrayReferenceNodeProperty.java:114)
at com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERProperty.java:155)
at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:340)
at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsSoleContent(XMLSerializer.java:593)
at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:324)
at com.sun.xml.bind.v2.runtime.property.ArrayReferenceNodeProperty.serializeListBody(ArrayReferenceNodeProperty.java:114)
at com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERProperty.java:155)
at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:340)
at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:696)
at com.sun.xml.bind.v2.runtime.property.SingleElementNodeProperty.serializeBody(SingleElementNodeProperty.java:152)
at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:340)
at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsSoleContent(XMLSerializer.java:593)
at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:324)
at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:494)
at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:315)
... 6 more
Exception in thread "main" org.docx4j.openpackaging.exceptions.Docx4JException: Problems applying bindings
at org.docx4j.openpackaging.parts.CustomXmlDataStoragePart.applyBindings(CustomXmlDataStoragePart.java:793)
at CustomXmlBinding.main(CustomXmlBinding.java:229)
Caused by: org.docx4j.openpackaging.exceptions.Docx4JException: Null DOM Doc
at org.docx4j.XmlUtils.transform(XmlUtils.java:642)
at org.docx4j.openpackaging.parts.CustomXmlDataStoragePart.applyBindings(CustomXmlDataStoragePart.java:787)
... 1 more
Caused by: java.lang.Throwable
at org.docx4j.XmlUtils.transform(XmlUtils.java:641)
... 2 more


I think this is related to the floating text boxes, and a vertical line that I had in my template. Like I was saying, I didnt have any issue before, and when I took those areas out of my template, it ran successfully.

However, there seems to be a bug, or I am misconfigued - Below is the structure of my bindings - as you can see, the person could have one or many employers, and each of those employers could have one or many projects.

<employers>
<employer>
<employerName />
<projects>
<project>
<projectName />
</project>
</projects>
</employer>
</employers>

I have configured my custom XML file to be configured where there are 2 employers. One employer has one project, and the other employer has two projects - like so :

<employers>
<employer>
<employerName />
<projects>
<project>
<projectName> Project 1 </projectName>
</project>
</projects>
</employer>

<employer>
<employerName />
<projects>
<project>
<projectName> Project 2 </projectName>
</project>
<project>
<projectName> Project 3 </projectName>
</project>
</projects>
</employer>
</employers>

When I have this in my document, the Employers print out as they should, but for the second employer, it prints the Project2 info twice, instead of Project2 then Project 3

here is how I had the binding set up for the projectrepeat section:

bindingrole=repeat&w:xpath=/resume[1]/employers/employer/projects&w:storeItemID={72FAEA80-BBA1-4063-876F-B1CEAAF6FD6C}

Is this correctly set up?

In my document, I had a table row with the Employers repeat, and imbedded in that table row, another table row with the Projects repeat

Re: Filling out a template - nested repeats

PostPosted: Wed Sep 15, 2010 1:32 am
by dcole
Playing with it a few minutes, i discovered that I could get it working like this:

bindingrole=repeat&w:xpath=/resume[1]/employers[1]/employer/projects&w:storeItemID={72FAEA80-BBA1-4063-876F-B1CEAAF6FD6C}

Is that the intended way?

Re: Filling out a template - nested repeats

PostPosted: Wed Sep 15, 2010 9:43 am
by jason
dcole wrote:[com.sun.istack.SAXException2: unable to marshal type "org.docx4j.wml.Pict" as an element because it is missing an @XmlRootElement annotation


I'll add that annotation. The new code seems to identify more cases similar to that.

dcole wrote:I could get it working like this:

bindingrole=repeat&w:xpath=/resume[1]/employers[1]/employer/projects&w:storeItemID={72FAEA80-BBA1-4063-876F-B1CEAAF6FD6C}


Either should work (ie with or without the [1]).

Are you able to attach (as a zip) your docx as a test case?

Re: Filling out a template - nested repeats

PostPosted: Wed Sep 15, 2010 11:51 pm
by dcole
I think the doc I am working on is proprietary to my employer, but if I have some time today I will see if I can whip up a test document.