Here is the code i use to fill the document

public byte[] createOdf() {
                try {
                        RhinoStreamTemplate templating = new 
RhinoStreamTemplate(new
ByteArrayInputStream(template));
                        // Fill with sample values.

                        List<InvoiceLineEntity> happenings = 
newInvoice.getLines();

                        final HashMap<String, HashMap<String, Object>> children 
= new
HashMap<String, HashMap<String, Object>>();

                        final List<Map<String, String>> general = new 
ArrayList<Map<String,
String>>();
                        for (int i = 0; i < happenings.size(); i++) {
                                InvoiceLineEntity current = happenings.get(i);
                                if (current.getChildId() == -1) {
                                        general.add(createLineMap(current));
                                } else {
                                        HashMap<String, Object> child = 
children.get(String.valueOf
(current.getChildId()));
                                        if (child == null) {
                                                child = new HashMap<String, 
Object>();
                                                
children.put(String.valueOf(current.getChildId()), child);
                                                child.put("childName", "Test");
                                                List<Map<String, String>> 
childLines = new ArrayList<Map<String,
String>>();
                                                child.put("lines", childLines);
                                        }
                                        List<Map<String, String>> lines = 
(List<Map<String, String>>)
child.get("lines");
                                        lines.add(createLineMap(current));
                                }
                        }

                        final List<HashMap<String, Object>> months = new
ArrayList<HashMap<String, Object>>();
                        months.addAll(children.values());
                        templating.setField("children", months);
                        templating.setField("general", general);

                        OdfGenerator.putParameters(templating, user);
                        OdfGenerator.putParameters(templating, getSettings());
                        ByteArrayOutputStream out = new ByteArrayOutputStream();
                        templating.saveTo(out);
                        return out.toByteArray();
                } catch (IOException e) {
                        LOGGER.error(e);
                } catch (TemplateException e) {
                        LOGGER.error(e);
                } catch (JDOMException e) {
                        LOGGER.error(e);
                }
                return null;
        }

        private ChildOptionsManager happeningsManager = null;

        public InvoicePdfOdf(Locale locale, ChildOptionsManager
newHappeningsManager) {
                super(locale);
                happeningsManager = newHappeningsManager;
        }

        private Map<String, String> createLineMap(InvoiceLineEntity event) {
                final Map<String, String> res = new HashMap<String, String>();
                res.put("description", event.getDescription());
                res.put("quantity", String.valueOf(event.getQuantity()));
                res.put("itemPrice", String.valueOf(event.getPricePerUnit()));
                res.put("lineTotal", String.valueOf(event.getTotalPrice()));
                res.put("lineVat", String.valueOf(event.getVat()));
                // if (happeningsManager != null) {
                // HappeningEvent real = (HappeningEvent) event;
                // res.put("happening", happeningsManager.getHappening
(real.getHappeningId()).getTitle());
                // } else {
                // res.put("happening", String.valueOf(event.getEventCode()));
                // }
                // if (event.getComment() != null) {
                // res.put("comment", htmlToText(event.getComment()));
                // } else {
                // res.put("comment", "");
                // }

                return res;
        }

On 19 jul, 19:38, Marteijn Nouwens <[email protected]> wrote:
> I mean that i have a repeting section. which has a table wich rows are
> repeated. I can send the template and piece of code.
>
> Marteijn
>
> On Jul 19, 3:09 pm, Guillaume Maillard <[email protected]>
> wrote:
>
>
>
> > Hi Marteijn,
>
> > It's not easy to help you without looking at the template and the code,
> > or more precisely what you mean by grouping children or repeating sections.
> > Do you mean  "OpenDocument section" or "group of lines in a table"?
>
> > To answer your question: yes it's possible to repeat section, and groups of
> > lines in tables.
>
> > Regards,
> > Guillaume
>
> > 2009/7/19 Marteijn Nouwens <[email protected]>
>
> > > Hello,
>
> > > I have an document in which i want to group childrne with each child
> > > having multible line on a table. I created the java code but using
> > > chil.get("lines") produces an script error. Is this possible?
>
> > > Marteijn Nouwens

Reply via email to