Re: cayenne+jasperreports problem

From: Alan Baltazar (acatalan..ahoo.com)
Date: Fri May 12 2006 - 06:09:09 EDT

  • Next message: Cris Daniluk: "Re: a...bug with pgsql and addPrefetch? (Cay 1.2B2)"

    thanks juergen

    --- Juergen Saar <juerge..saar.org> wrote:

    > Here a simple JRDataSource template:
    >
    > /*
    > * Created on 12.05.2006
    > */
    > package org.jsaar.report;
    >
    > import java.util.Iterator;
    > import java.util.List;
    >
    > import org.apache.commons.jxpath.JXPathContext;
    > import org.objectstyle.cayenne.DataObject;
    >
    > import net.sf.jasperreports.engine.JRDataSource;
    > import net.sf.jasperreports.engine.JRException;
    > import net.sf.jasperreports.engine.JRField;
    >
    > public class JsDataSource extends Object implements JRDataSource {
    > private List data = null;
    > private Iterator iterator = null;
    > private DataObject dataObject = null;
    >
    > /**
    > * Constructor with List usually from SelectQuery
    > *
    > *..aram businessObjects
    > */
    > public JsDataSource(List businessObjects) {
    > super();
    > setData(businessObjects);
    > }
    >
    > /**
    > * setter for List
    > *
    > *..aram list
    > */
    > public void setData(List list) {
    > data = list;
    > iterator = data.iterator();
    > }
    >
    > /* (non-Javadoc)
    > *..ee net.sf.jasperreports.engine.JRDataSource#getFieldValue(
    > net.sf.jasperreports.engine.JRField)
    > */
    > public Object getFieldValue(JRField field) throws JRException {
    > String name = field.getName();
    > JXPathContext context = JXPathContext.newContext(dataObject);
    > Object obj = context.getValue(name);
    > return (obj == null) ? null : obj.toString();
    > }
    >
    > /* (non-Javadoc)
    > *..ee net.sf.jasperreports.engine.JRDataSource#next()
    > */
    > public boolean next() throws JRException {
    > boolean result = iterator.hasNext();
    > if (result) {
    > dataObject = (DataObject) iterator.next();
    > }
    > return result;
    > }
    >
    > }
    >
    >
    > 2006/5/12, Alan Baltazar <acatalan..ahoo.com>:
    > >
    > >
    > > DataRows seem to be the only solution i could think of to wrap the
    > > JRDataSource
    > > implementation, which is required by jasperreports to read the datasource
    > > data.
    > > JRDataSource is a wrapper hashmap for reading the rows from a datasource.
    > > i don't know
    > > much about dataobjects to implement this .... if you do, please let me
    > > know how.
    > >
    > > --- Juergen Saar <juerge..saar.org> wrote:
    > >
    > > > Why do you work on DataRows ... DataObjects are much more like
    > > > BusinessObjects.
    > > >
    > > > If you work on DataObjects and there are some getters for
    > > > transient informations coming from business-logic
    > > > it can help a lot.
    > > >
    > > > Just one more hint:
    > > > reading content of DataObjects with jxpath is really cool.
    > > >
    > >
    >

    __________________________________________________
    Do You Yahoo!?
    Tired of spam? Yahoo! Mail has the best spam protection around
    http://mail.yahoo.com



    This archive was generated by hypermail 2.0.0 : Fri May 12 2006 - 06:09:38 EDT