Page 1 of 1

Repeat Data Binding - what can repeat?

PostPosted: Fri Oct 15, 2010 6:27 am
by dcole
[moderator: split from original post]

does this still only work with rows of a table? Is it possible to repeat across the columns of the word document? Say I had a list of things I wanted to somehow repeat ,across the page instead of down, with a comma after each one or a bar between them or something.

Re: Repeat Data Binding - what can repeat?

PostPosted: Fri Oct 15, 2010 12:50 pm
by jason
Interesting question :-)

You can repeat any paragraph level content (ie clone one or more paragraphs or tables).

And I think it has always worked for a repeating run.

Certainly you can make a run into a rich text control and add a repeat to that. Then you put a plain text control inside that, and add the content you want. You problem is going to be that your separator (say you put a comma in the rich text control, after the plain text control) appears after the last item as well. Might need to think of an elegant way to handle this. Maybe its just an extra attribute on the repeat tag which specifues the separator text?

You can also repeat a table cell (following a patch i just committed). I guess you might run out of room horizontally, if your cell width settings are fixed (so don't make them fixed).

As to repeating columns: not quite at the moment. You can put sectPr in sdtContent (although Word 2007 UI looks a bit strange when you do), but the number of columns is given by w:cols/@w:num, and there is currently no way to change that attribute. It would be interesting to extend the conventions to enable these sorts of non-textual changes.

Re: Repeat Data Binding - what can repeat?

PostPosted: Fri Nov 05, 2010 7:13 am
by dcole
Jason, I think there is a bug in the repeating part.

Behold the XML:
Code: Select all
<employee>
   <projectslist>
      <projects>
         <roleslist>
            <roles>
               <roleskillslist>
                  <roleSkills>Java</roleSkills>
                  <roleSkills>Groovy</roleSkills>
                  <roleSkills>Grails</roleSkills>
               </roleskillslist>
               <rolestoolslist>
                  <roleTools>Eclipse</roleTools>
                  <roleTools>Subversion</roleTools>
                  <roleTools>Tomcat</roleTools>
                  <roleTools>SQL</roleTools>
               </rolestoolslist>
            </roles>
         </roleslist>
      </projects>
   </projectslist>
</employee>


When I am using something like that, I can not get the tools or skills to repeat correctly. The new instructions say to set the binding on "roleSkills" for example, but when I do this, I get content controls created, but the content is not actually bound - so they are blank. I thought it was a problem with nested repeats, but I have no problem repeating projects, repeating roles iwthin projects..but maybe it breaks when it is triple nested?

Re: Repeat Data Binding - what can repeat?

PostPosted: Fri Nov 05, 2010 8:10 am
by dcole
I just noticed that it is actualyl giving me an exception:


org.docx4j.openpackaging.exceptions.Docx4JException: Problems evaluating xpath '[1]/employee/projectslist/projects[1]/roleslist/roles[1]/roleskillslist/roleSkills'
at org.docx4j.openpackaging.parts.XmlPart.xpathGetString(XmlPart.java:138)
at org.docx4j.openpackaging.parts.CustomXmlDataStoragePart.xpathGetString(CustomXmlDataStoragePart.java:949)
at sun.reflect.GeneratedMethodAccessor47.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.xalan.extensions.ExtensionHandlerJavaPackage.callFunction(ExtensionHandlerJavaPackage.java:300)
at org.apache.xalan.extensions.ExtensionHandlerJavaPackage.callFunction(ExtensionHandlerJavaPackage.java:440)
at org.apache.xalan.extensions.ExtensionsTable.extFunction(ExtensionsTable.java:222)
at org.apache.xalan.transformer.TransformerImpl.extFunction(TransformerImpl.java:473)
at org.apache.xpath.functions.FuncExtFunction.execute(FuncExtFunction.java:208)
:
at org.docx4j.XmlUtils.transform(XmlUtils.java:740)
at org.docx4j.XmlUtils.transform(XmlUtils.java:664)
at org.docx4j.openpackaging.parts.CustomXmlDataStoragePart.applyBindings(CustomXmlDataStoragePart.java:921)
at CustomXmlBinding.main(CustomXmlBinding.java:138)
Caused by: javax.xml.xpath.XPathExpressionException
at org.apache.xpath.jaxp.XPathImpl.evaluate(XPathImpl.java:295)
at org.apache.xpath.jaxp.XPathImpl.evaluate(XPathImpl.java:371)
at org.docx4j.openpackaging.parts.XmlPart.xpathGetString(XmlPart.java:134)
... 81 more
Caused by: javax.xml.transform.TransformerException: A location path was expected, but the following token was encountered: [
at org.apache.xpath.compiler.XPathParser.error(XPathParser.java:610)
at org.apache.xpath.compiler.XPathParser.LocationPath(XPathParser.java:1601)
at org.apache.xpath.compiler.XPathParser.PathExpr(XPathParser.java:1317)

Re: Repeat Data Binding - what can repeat?

PostPosted: Fri Nov 05, 2010 10:34 am
by jason
Fixed just now in http://dev.plutext.org/trac/docx4j/changeset/1287

Please confirm ...

Re: Repeat Data Binding - what can repeat?

PostPosted: Sat Nov 06, 2010 2:11 am
by dcole
Seems to have done the trick. Just so you know to build this I had to change the version of wagon-svn to 1.9 instead of 1.8 in the pom. Thanks for the quick turnaround!

Re: Repeat Data Binding - what can repeat?

PostPosted: Sat Nov 06, 2010 2:17 am
by dcole
By the way I just tried to get a horizontal repeat going on a table cell - it worked like a charm! I like that ability! I can live with a trailing comma, so this is going to work good for dumping a List from JAXB marshal into a word doc! thumbs up

Re: Repeat Data Binding - what can repeat?

PostPosted: Tue Nov 09, 2010 10:20 pm
by jason
Great, thanks for the feedback Derek :-)