coldfusionrailoopendocument

Using jopendocument with coldfusion/railo, how to add table row?


I'm using jopendocument 1.2 with Railo 3.3.1.000

from http://www.jopendocument.org/start_text_2.html

List<Map<String, String>> months = new ArrayList<Map<String, String>>();
months.add(createMap("January", "-12", "3"));
months.add(createMap("February", "-8", "5"));
months.add(createMap("March", "-5", "12"));
months.add(createMap("April", "-1", "15"));
months.add(createMap("May", "3", "21"));
template.setField("months", months);

How to write that code in cfml, or anyone have experience with jopendocument to add row in odt template file with cfml?


Solution

  • List<Map<String, String>> months = new ArrayList<Map<String, String>>();

    In CF terms, that code creates an array of structures. Because java is strongly typed the code uses generics to indicate what type of objects each one contains

        List< Map<...> >          // Array containing structures 
        Map< String, String >     // Structure containing "String" values
    

    Fortunately CF arrays are java.util.List objects internally and structures are java.util.Map objects. So you only need to create a CF array of structures with the proper keys and values. Then pass the array into template.setField(...).

    I was not sure which keys to use in the structure, so I downloaded the "test.odt" template from jOpenDocument-template-1.2.zip. It revealed each structure should contain three (3) keys, one for each column in the table: name, min, max. As long as you populate the structures with strings, this should work:

    // Create an array of structures. Each structure represents a table row. 
    // The key names for columns 1-3 are: "name", "min", "max"
    months = [
                {name="January", min="-12", max="3"}
                , {name="February", min="-8", max="5"}
                , {name="March", min="-5", max="12"}
                , {name="April", min="-1", max="15"}
                , {name="May", min="3", max="21"}
                , {name="June", min="5", max="32"}
            ];  
    
    // populate table rows
    template.setField("months", months);