You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Alan Baltazar <ac...@yahoo.com> on 2006/05/11 07:07:58 UTC
cayenne+jasperreports problem
hello,
i implemented this
http://www.objectstyle.org/confluence/display/CAY/Jasper+Integration
to integrate cayenne and jasperreports for a web application (no spring framework, just
straight cayenne,struts web app). my problem here, is that, I get a class cast exception
for this class, DataRowDataSource (see arrow below).
public class DataRowDataSource implements JRDataSource {
private Iterator rowIterator;
private DataRow activeRow;
public DataRowDataSource(List dataRowList) {
rowIterator = dataRowList.iterator();
activeRow = (DataRow)rowIterator.next(); <--- cast problem here (posted sample
didn't have the (DataRow) cast, i
added it here to compile)
}
public boolean next() throws JRException {
boolean hasNext = rowIterator.hasNext();
if (hasNext) {
activeRow = (DataRow) rowIterator.next();
}
return hasNext;
}
public Object getFieldValue(JRField field) throws JRException {
return activeRow.get(field.getName());
}
}
has anyone implemented this sample? if yes, how did you fix this problem? I'm using the
latest cayenne, struts, jasperreports versions.
Alan,
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Re: cayenne+jasperreports problem
Posted by Alan Baltazar <ac...@yahoo.com>.
thanks juergen
--- Juergen Saar <ju...@jsaar.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
> *
> * @param businessObjects
> */
> public JsDataSource(List businessObjects) {
> super();
> setData(businessObjects);
> }
>
> /**
> * setter for List
> *
> * @param list
> */
> public void setData(List list) {
> data = list;
> iterator = data.iterator();
> }
>
> /* (non-Javadoc)
> * @see 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)
> * @see 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 <ac...@yahoo.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 <ju...@jsaar.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
Re: cayenne+jasperreports problem
Posted by Juergen Saar <ju...@jsaar.org>.
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
*
* @param businessObjects
*/
public JsDataSource(List businessObjects) {
super();
setData(businessObjects);
}
/**
* setter for List
*
* @param list
*/
public void setData(List list) {
data = list;
iterator = data.iterator();
}
/* (non-Javadoc)
* @see 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)
* @see 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 <ac...@yahoo.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 <ju...@jsaar.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.
> >
>
Re: cayenne+jasperreports problem
Posted by Alan Baltazar <ac...@yahoo.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 <ju...@jsaar.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.
>
> 2006/5/11, Alan Baltazar <ac...@yahoo.com>:
> >
> > hello,
> >
> > i implemented this
> > http://www.objectstyle.org/confluence/display/CAY/Jasper+Integration
> > to integrate cayenne and jasperreports for a web application (no spring
> > framework, just
> > straight cayenne,struts web app). my problem here, is that, I get a class
> > cast exception
> > for this class, DataRowDataSource (see arrow below).
> >
> > public class DataRowDataSource implements JRDataSource {
> >
> > private Iterator rowIterator;
> > private DataRow activeRow;
> >
> > public DataRowDataSource(List dataRowList) {
> > rowIterator = dataRowList.iterator();
> > activeRow = (DataRow)rowIterator.next(); <--- cast problem here
> > (posted sample
> > didn't have the
> > (DataRow) cast, i
> > added it here to
> > compile)
> > }
> >
> > public boolean next() throws JRException {
> > boolean hasNext = rowIterator.hasNext();
> > if (hasNext) {
> > activeRow = (DataRow) rowIterator.next();
> > }
> >
> > return hasNext;
> > }
> >
> > public Object getFieldValue(JRField field) throws JRException {
> > return activeRow.get(field.getName());
> > }
> >
> > }
> >
> > has anyone implemented this sample? if yes, how did you fix this problem?
> > I'm using the
> > latest cayenne, struts, jasperreports versions.
> >
> > Alan,
> >
> >
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Re: cayenne+jasperreports problem
Posted by Juergen Saar <ju...@jsaar.org>.
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.
2006/5/11, Alan Baltazar <ac...@yahoo.com>:
>
> hello,
>
> i implemented this
> http://www.objectstyle.org/confluence/display/CAY/Jasper+Integration
> to integrate cayenne and jasperreports for a web application (no spring
> framework, just
> straight cayenne,struts web app). my problem here, is that, I get a class
> cast exception
> for this class, DataRowDataSource (see arrow below).
>
> public class DataRowDataSource implements JRDataSource {
>
> private Iterator rowIterator;
> private DataRow activeRow;
>
> public DataRowDataSource(List dataRowList) {
> rowIterator = dataRowList.iterator();
> activeRow = (DataRow)rowIterator.next(); <--- cast problem here
> (posted sample
> didn't have the
> (DataRow) cast, i
> added it here to
> compile)
> }
>
> public boolean next() throws JRException {
> boolean hasNext = rowIterator.hasNext();
> if (hasNext) {
> activeRow = (DataRow) rowIterator.next();
> }
>
> return hasNext;
> }
>
> public Object getFieldValue(JRField field) throws JRException {
> return activeRow.get(field.getName());
> }
>
> }
>
> has anyone implemented this sample? if yes, how did you fix this problem?
> I'm using the
> latest cayenne, struts, jasperreports versions.
>
> Alan,
>
>
Re: cayenne+jasperreports problem
Posted by Alan Baltazar <ac...@yahoo.com>.
maybe u should post an updated version for the new Jasper 1.2 . cayenne+jasper should
be one of those needed samples by newbie cayenne app developers..
--- Cris Daniluk <cr...@gmail.com> wrote:
> FYI, this was written for Jasper 1.1. 1.2 has some significant changes
> that probably lead to an easier way to do integration w/Cayenne. I
> have no idea if this works with 1.2 or not.
>
> Cris
>
> On 5/11/06, Alan Baltazar <ac...@yahoo.com> wrote:
> > hello,
> >
> > i implemented this
> > http://www.objectstyle.org/confluence/display/CAY/Jasper+Integration
> > to integrate cayenne and jasperreports for a web application (no spring framework,
> just
> > straight cayenne,struts web app). my problem here, is that, I get a class cast
> exception
> > for this class, DataRowDataSource (see arrow below).
> >
> > public class DataRowDataSource implements JRDataSource {
> >
> > private Iterator rowIterator;
> > private DataRow activeRow;
> >
> > public DataRowDataSource(List dataRowList) {
> > rowIterator = dataRowList.iterator();
> > activeRow = (DataRow)rowIterator.next(); <--- cast problem here (posted
> sample
> > didn't have the (DataRow) cast, i
> > added it here to compile)
> > }
> >
> > public boolean next() throws JRException {
> > boolean hasNext = rowIterator.hasNext();
> > if (hasNext) {
> > activeRow = (DataRow) rowIterator.next();
> > }
> >
> > return hasNext;
> > }
> >
> > public Object getFieldValue(JRField field) throws JRException {
> > return activeRow.get(field.getName());
> > }
> >
> > }
> >
> > has anyone implemented this sample? if yes, how did you fix this problem? I'm using
> the
> > latest cayenne, struts, jasperreports versions.
> >
> > Alan,
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam? Yahoo! Mail has the best spam protection around
> > http://mail.yahoo.com
> >
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Re: cayenne+jasperreports problem
Posted by Cris Daniluk <cr...@gmail.com>.
FYI, this was written for Jasper 1.1. 1.2 has some significant changes
that probably lead to an easier way to do integration w/Cayenne. I
have no idea if this works with 1.2 or not.
Cris
On 5/11/06, Alan Baltazar <ac...@yahoo.com> wrote:
> hello,
>
> i implemented this
> http://www.objectstyle.org/confluence/display/CAY/Jasper+Integration
> to integrate cayenne and jasperreports for a web application (no spring framework, just
> straight cayenne,struts web app). my problem here, is that, I get a class cast exception
> for this class, DataRowDataSource (see arrow below).
>
> public class DataRowDataSource implements JRDataSource {
>
> private Iterator rowIterator;
> private DataRow activeRow;
>
> public DataRowDataSource(List dataRowList) {
> rowIterator = dataRowList.iterator();
> activeRow = (DataRow)rowIterator.next(); <--- cast problem here (posted sample
> didn't have the (DataRow) cast, i
> added it here to compile)
> }
>
> public boolean next() throws JRException {
> boolean hasNext = rowIterator.hasNext();
> if (hasNext) {
> activeRow = (DataRow) rowIterator.next();
> }
>
> return hasNext;
> }
>
> public Object getFieldValue(JRField field) throws JRException {
> return activeRow.get(field.getName());
> }
>
> }
>
> has anyone implemented this sample? if yes, how did you fix this problem? I'm using the
> latest cayenne, struts, jasperreports versions.
>
> Alan,
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
Re: cayenne+jasperreports problem
Posted by Alan Baltazar <ac...@yahoo.com>.
ok. this one seems to fix the problem. i didn't know who have a choice to return a list
of objects or datarows,
DataContext dataContext = DataContext.createDataContext();
String queryName = report.getQuery().getText();
SQLTemplate query = new SQLTemplate(Artist.class, queryName , true);
//query.isFetchingDataRows();
query.setFetchingDataRows(true); <----flag to return list of objects or datarows
List resultSet = dataContext.performQuery(query);
--- Alan Baltazar <ac...@yahoo.com> wrote:
>
> i'm new at using DataRows. i used SQLTemplate to returned the list of
> dataobjects....instead of a list of DataRows. i'm trying to figure out how to go about
> this returning a list of DataRows from a SQLTemplate....does anyone know of a cayenne
> class that can do this? so i don't have to resort to writing another set of code to fix
> this problem..i'm trying to use as much of cayenne api's as possible.
>
> --- Tobias.Schoessler@unvienna.org wrote:
>
> > Alan, did you make sure that the list you hand in contains DataRows? e.g. used
> > SQLTemplate to create the list and set to return DataRows?
> >
> > Alan Baltazar <ac...@yahoo.com> wrote:
> > hello,
> >
> > i implemented this
> > http://www.objectstyle.org/confluence/display/CAY/Jasper+Integration
> > to integrate cayenne and jasperreports for a web application (no spring framework,
> just
> > straight cayenne,struts web app). my problem here, is that, I get a class cast
> > exception
> > for this class, DataRowDataSource (see arrow below).
> >
> > public class DataRowDataSource implements JRDataSource {
> >
> > private Iterator rowIterator;
> > private DataRow activeRow;
> >
> > public DataRowDataSource(List dataRowList) {
> > rowIterator = dataRowList.iterator();
> > activeRow = (DataRow)rowIterator.next(); <--- cast problem here (posted
> sample
> >
> > didn't have the (DataRow) cast, i
> > added it here to compile)
> > }
> >
> > public boolean next() throws JRException {
> > boolean hasNext = rowIterator.hasNext();
> > if (hasNext) {
> > activeRow = (DataRow) rowIterator.next();
> > }
> >
> > return hasNext;
> > }
> >
> > public Object getFieldValue(JRField field) throws JRException {
> > return activeRow.get(field.getName());
> > }
> >
> > }
> >
> > has anyone implemented this sample? if yes, how did you fix this problem? I'm using
> > the
> > latest cayenne, struts, jasperreports versions.
> >
> > Alan,
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam? Yahoo! Mail has the best spam protection around
> > http://mail.yahoo.com
> >
> > ___
> > sent via WebmailLight 3.1.9
> >
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Re: cayenne+jasperreports problem
Posted by Alan Baltazar <ac...@yahoo.com>.
i'm new at using DataRows. i used SQLTemplate to returned the list of
dataobjects....instead of a list of DataRows. i'm trying to figure out how to go about
this returning a list of DataRows from a SQLTemplate....does anyone know of a cayenne
class that can do this? so i don't have to resort to writing another set of code to fix
this problem..i'm trying to use as much of cayenne api's as possible.
--- Tobias.Schoessler@unvienna.org wrote:
> Alan, did you make sure that the list you hand in contains DataRows? e.g. used
> SQLTemplate to create the list and set to return DataRows?
>
> Alan Baltazar <ac...@yahoo.com> wrote:
> hello,
>
> i implemented this
> http://www.objectstyle.org/confluence/display/CAY/Jasper+Integration
> to integrate cayenne and jasperreports for a web application (no spring framework, just
> straight cayenne,struts web app). my problem here, is that, I get a class cast
> exception
> for this class, DataRowDataSource (see arrow below).
>
> public class DataRowDataSource implements JRDataSource {
>
> private Iterator rowIterator;
> private DataRow activeRow;
>
> public DataRowDataSource(List dataRowList) {
> rowIterator = dataRowList.iterator();
> activeRow = (DataRow)rowIterator.next(); <--- cast problem here (posted sample
>
> didn't have the (DataRow) cast, i
> added it here to compile)
> }
>
> public boolean next() throws JRException {
> boolean hasNext = rowIterator.hasNext();
> if (hasNext) {
> activeRow = (DataRow) rowIterator.next();
> }
>
> return hasNext;
> }
>
> public Object getFieldValue(JRField field) throws JRException {
> return activeRow.get(field.getName());
> }
>
> }
>
> has anyone implemented this sample? if yes, how did you fix this problem? I'm using
> the
> latest cayenne, struts, jasperreports versions.
>
> Alan,
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
> ___
> sent via WebmailLight 3.1.9
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Re: cayenne+jasperreports problem
Posted by To...@unvienna.org.
Alan, did you make sure that the list you hand in contains DataRows? e.g. used SQLTemplate to create the list and set to return DataRows?
Alan Baltazar <ac...@yahoo.com> wrote:
hello,
i implemented this
http://www.objectstyle.org/confluence/display/CAY/Jasper+Integration
to integrate cayenne and jasperreports for a web application (no spring framework, just
straight cayenne,struts web app). my problem here, is that, I get a class cast exception
for this class, DataRowDataSource (see arrow below).
public class DataRowDataSource implements JRDataSource {
private Iterator rowIterator;
private DataRow activeRow;
public DataRowDataSource(List dataRowList) {
rowIterator = dataRowList.iterator();
activeRow = (DataRow)rowIterator.next(); <--- cast problem here (posted sample
didn't have the (DataRow) cast, i
added it here to compile)
}
public boolean next() throws JRException {
boolean hasNext = rowIterator.hasNext();
if (hasNext) {
activeRow = (DataRow) rowIterator.next();
}
return hasNext;
}
public Object getFieldValue(JRField field) throws JRException {
return activeRow.get(field.getName());
}
}
has anyone implemented this sample? if yes, how did you fix this problem? I'm using the
latest cayenne, struts, jasperreports versions.
Alan,
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
___
sent via WebmailLight 3.1.9