Le 07/06/2011 21:14, Kaz a écrit :
Hi

I am a newbie to JOpenDocument and have a scenario where I need to use
nested lists.
I can create table rows using a list - this is fine as per the months
example.

My problem is that one of the fields in the above loop needs to be a
(sub)list - so nested loops

row1field1             row1field2
row1field3a
row1field3b
row1field3c
---------------------------------------------------------
row2field1             row2field2
row2field3a
row2field3b
row2field3c
---------------------------------------------------------
and so on

Firstly is this possible?
and if so can someone please advise me on how this can be done?

Sure, you just a have to a bullet point list inside a row with a "foreach". I've attached a simple example.

HTH
Sylvain

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.jopendocument.dom.OOUtils;
import org.jopendocument.dom.template.EngineTemplate;
import org.jopendocument.dom.template.RhinoTemplate;

public class NestedTemplate {

    public static void main(String[] args) {
        try {
            File templateFile = new File("template/nested.odt");
            // Load the template.
            EngineTemplate template = new RhinoTemplate(templateFile);

            // Fill with sample values.
            final List<Map<String, Object>> months = new ArrayList<Map<String, 
Object>>();
            months.add(createMap("January", "31", "3"));
            months.add(createMap("February", "29", "5", "7", "9"));
            months.add(createMap("March", "31", "12", "14"));
            template.setField("months", months);

            // Save and Open the document with OpenOffice.org !
            OOUtils.open(template.saveAs(new File("out.odt")));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static Map<String, Object> createMap(String n, String field2, 
String... field3) {
        final Map<String, Object> res = new HashMap<String, Object>();
        res.put("name", n);
        res.put("field2", field2);
        res.put("field3", Arrays.asList(field3));
        return res;
    }
}

Attachment: nested.odt
Description: application/vnd.oasis.opendocument.text

Reply via email to