Continuing the soliloquy...
I got past the Module exception by allowing the configuration map to be
null when building the JRProperties settings so it just uses default
settings.
I'm still having issues grasping the logic of getting the correct
output. Using the OutputStream as I mentioned before half works. HTML
doesn't display, CSV comes out good, PDF doesn't work and complains of
document type "text/plain", while XLS returns
java.lang.ClassNotFoundException
org.apache.poi.hssf.usermodel.HSSFCellStyle (maybe this is related to
the same issues with the JasperReports jar dependency not working)
So sort of progress, but not really. It doesn't seem like setting the
content-type of the OutputStream does anything worthwhile. Can someone
help explain? I get the feeling the OutputStream I'm using/or how I'm
using isn't right.
@Inject private Response resp;
private OutputStream os;
@Property @Persist
private ExportFormat formMode;
@Component
private Submit CSV;
@Component
private Submit HTML;
@Component
private Submit PDF;
@Component
private Submit XLS;
void onSelectedFromCSV(){
formMode = ExportFormat.CSV;
try {
os = resp.getOutputStream("text/comma-separated-values");
debug("OutputStream content-type="+"text/comma-separated-values");
} catch (IOException e) {
error(e.toString());
throw new TapestryException("Could not get CSV output stream", e);
}
}
void onSelectedFromHTML(){
formMode= ExportFormat.HTML;
try {
os = resp.getOutputStream("text/html");
debug("OutputStream content-type="+"text/html");
} catch (IOException e) {
error(e.toString());
throw new TapestryException("Could not get HTML output stream", e);
}
}
void onSelectedFromPDF(){
formMode = ExportFormat.PDF;
try {
os = resp.getOutputStream("application/pdf");
debug("OutputStream content-type="+"application/pdf");
} catch (IOException e) {
error(e.toString());
throw new TapestryException("Could not get PDF output stream", e);
}
}
void onSelectedFromXLS(){
formMode = ExportFormat.XLS;
try {
os = resp.getOutputStream("application/vnd.ms-excel");
debug("OutputStream content-type="+"application/vnd.ms-excel");
} catch (IOException e) {
error(e.toString());
throw new TapestryException("Could not get XLS output stream", e);
}
}
Thanks,
Rich
Rich wrote:
Hi again,
well it seems the source code wasn't that involved, just a nice
wrapper mostly over the file formats. It doesn't seem to have built-in
JDBC connection support, so I wrote a modified version that takes an
Object for dataSource and then dictates the proper
JasperFillManager.FillReport method depending on a JRDataSource or
Connection object. That aside, I could use some advice into applying
the FillAndExport method :
/**
* export the report.
*
* @param inputResource the input resource (report template file
".jrxml")
* @param format the output format
* @param parameterMap the parameter map
* @param dataSource the datasource. Either a JDBC SQL
Connection or JRDataSource object
* @param outputStream the output stream
*/
public void fillAndExport(Resource inputResource, ExportFormat
format, Map parameterMap, Object dataSource, OutputStream outputStream)
{
JasperPrint jasperPrint = fillReport(inputResource,
parameterMap, dataSource);
export(jasperPrint, format, outputStream);
}
In older code at my company (JSP-Servlet based), we typically build
the parameterMap, hand load the inputResource in a File object, and
then define the format/content-type in the HTTPResponse and connect
the HTTPResponse's outputStream into the export method. At this point
the intended results are displayed.
To mirror this, I found the Response service in Tapestry, and use the
getOutputStream(contentType) method, setting the appropriate
content-type string in the call. Can I expect this to work as I intend
(displaying/triggering the browser through this stream)?
I'm calling the function like this:
public void onSuccessFromRepForm(){
Map parameterMap = loadParameters(reportTitle);
Connection conn = null;
try{
conn = Report.getConnection();
rs.fillAndExport(new
ContextResource(cimpl,reportTitle+".xml"), formMode, parameterMap,
conn, os);
}catch (Exception e){
System.out.println("Caught exception while trying to
execute the report fillAndExport service method.");
throw new TapestryException("Issue executing report", e);
} finally {
if(conn != null){
try {
conn.close();
} catch (SQLException e) {
System.out.println("Could not close the JDBC
connection!!");
}
}
}
}
cimpl is an injection of the Tapestry Context service, formMode is a
page property, and os is the loaded Response OutputStream. When I try
to test this (this was before I made the JDBC Connection change) I get
the following Exception from the ChenilleKitReportsModule (:
Exception constructing service 'ReportsService': Error invoking
service builder method
org.chenillekit.reports.ChenilleKitReportsModule.buildReportsService(Logger,Map)
(at ChenilleKitReportsModule.java:43) (for service 'ReportsService'):
Parameter configuration was null.
From the module:
public static ReportsService buildReportService(Logger logger,
Map<String, Resource> configuration)
{
return new ReportsServiceImpl(logger,
configuration.get(ReportsService.CONFIG_RESOURCE_KEY));
}
I'm assuming this is because I don't have a line in my AppModule where
i add to the configuration a mapping for "jasperreports.properties"
(resolution of ReportsService.CONFIG_RESOURCE_KEY), but I'm also not
sure what this is supposed to be mapping to.
Things break worse when I use my own extended version including JDBC
Connections:
Caused by: java.lang.RuntimeException: Exception constructing service
'ValueEncoderSource': Error invoking service builder method
org.apache.tapestry5.services.TapestryModule.buildValueEncoderSource(Map,
InvalidationEventHub) (at TapestryModule.java:1910) (for service
'ValueEncoderSource'): Error invoking service contribution method
org.apache.tapestry5.hibernate.HibernateModule.contributeValueEncoderSource(MappedConfiguration,
boolean, HibernateSessionSource, Session, TypeCoercer, PropertyAccess,
LoggerSource): Exception constructing service
'HibernateSessionSource': Error invoking service builder method
org.apache.tapestry5.hibernate.HibernateCoreModule.buildHibernateSessionSource(Logger,
List, RegistryShutdownHub) (at HibernateCoreModule.java:123) (for
service 'HibernateSessionSource'):
org/apache/commons/collections/map/LRUMap
at
org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator.obtainObjectFromCreator(JustInTimeObjectCreator.java:78)
at
org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator.createObject(JustInTimeObjectCreator.java:57)
at
$ValueEncoderSource_12a14ccbea5.delegate($ValueEncoderSource_12a14ccbea5.java)
at
$ValueEncoderSource_12a14ccbea5.getValueEncoder($ValueEncoderSource_12a14ccbea5.java)
at
org.apache.tapestry5.internal.services.ComponentDefaultProviderImpl.defaultValueEncoder(ComponentDefaultProviderImpl.java:116)
at
$ComponentDefaultProvider_12a14ccbe71.defaultValueEncoder($ComponentDefaultProvider_12a14ccbe71.java)
at
org.apache.tapestry5.corelib.components.Loop.defaultEncoder(Loop.java:304)
at
org.apache.tapestry5.corelib.components.Loop.containingPageDidLoad(Loop.java)
at
org.apache.tapestry5.internal.structure.ComponentPageElementImpl$4.run(ComponentPageElementImpl.java:98)
at
org.apache.tapestry5.internal.structure.ComponentPageElementImpl.invoke(ComponentPageElementImpl.java:933)
... 55 more
Caused by: java.lang.RuntimeException: Error invoking service builder
method
org.apache.tapestry5.services.TapestryModule.buildValueEncoderSource(Map,
InvalidationEventHub) (at TapestryModule.java:1910) (for service
'ValueEncoderSource'): Error invoking service contribution method
org.apache.tapestry5.hibernate.HibernateModule.contributeValueEncoderSource(MappedConfiguration,
boolean, HibernateSessionSource, Session, TypeCoercer, PropertyAccess,
LoggerSource): Exception constructing service
'HibernateSessionSource': Error invoking service builder method
org.apache.tapestry5.hibernate.HibernateCoreModule.buildHibernateSessionSource(Logger,
List, RegistryShutdownHub) (at HibernateCoreModule.java:123) (for
service 'HibernateSessionSource'):
org/apache/commons/collections/map/LRUMap
at
org.apache.tapestry5.ioc.internal.ServiceBuilderMethodInvoker.createObject(ServiceBuilderMethodInvoker.java:76)
at
org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator$1.invoke(OperationTrackingObjectCreator.java:45)
at
org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:68)
at
org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:68)
at
org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:941)
at
org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator.createObject(OperationTrackingObjectCreator.java:49)
at
org.apache.tapestry5.ioc.internal.SingletonServiceLifecycle.createService(SingletonServiceLifecycle.java:29)
at
org.apache.tapestry5.ioc.internal.LifecycleWrappedServiceCreator.createObject(LifecycleWrappedServiceCreator.java:46)
at
org.apache.tapestry5.ioc.internal.AdvisorStackBuilder.createObject(AdvisorStackBuilder.java:60)
at
org.apache.tapestry5.ioc.internal.InterceptorStackBuilder.createObject(InterceptorStackBuilder.java:52)
at
org.apache.tapestry5.ioc.internal.RecursiveServiceCreationCheckWrapper.createObject(RecursiveServiceCreationCheckWrapper.java:60)
at
org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator$1.invoke(OperationTrackingObjectCreator.java:45)
at
org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:68)
at
org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:68)
at
org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:941)
at
org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator.createObject(OperationTrackingObjectCreator.java:49)
at
org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator.obtainObjectFromCreator(JustInTimeObjectCreator.java:68)
... 64 more
Caused by: java.lang.RuntimeException: Error invoking service
contribution method
org.apache.tapestry5.hibernate.HibernateModule.contributeValueEncoderSource(MappedConfiguration,
boolean, HibernateSessionSource, Session, TypeCoercer, PropertyAccess,
LoggerSource): Exception constructing service
'HibernateSessionSource': Error invoking service builder method
org.apache.tapestry5.hibernate.HibernateCoreModule.buildHibernateSessionSource(Logger,
List, RegistryShutdownHub) (at HibernateCoreModule.java:123) (for
service 'HibernateSessionSource'):
org/apache/commons/collections/map/LRUMap
at
org.apache.tapestry5.ioc.internal.ContributionDefImpl.invokeMethod(ContributionDefImpl.java:122)
at
org.apache.tapestry5.ioc.internal.ContributionDefImpl.contribute(ContributionDefImpl.java:71)
at
org.apache.tapestry5.ioc.internal.RegistryImpl$4.run(RegistryImpl.java:470)
at
org.apache.tapestry5.ioc.internal.OperationTrackerImpl$1.invoke(OperationTrackerImpl.java:52)
at
org.apache.tapestry5.ioc.internal.OperationTrackerImpl$1.invoke(OperationTrackerImpl.java:50)
at
org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:68)
at
org.apache.tapestry5.ioc.internal.OperationTrackerImpl.run(OperationTrackerImpl.java:48)
at
org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.run(PerThreadOperationTracker.java:56)
at
org.apache.tapestry5.ioc.internal.RegistryImpl.addToMappedConfiguration(RegistryImpl.java:466)
at
org.apache.tapestry5.ioc.internal.RegistryImpl.getMappedConfiguration(RegistryImpl.java:416)
at
org.apache.tapestry5.ioc.internal.ServiceResourcesImpl$3.invoke(ServiceResourcesImpl.java:126)
at
org.apache.tapestry5.ioc.internal.ServiceResourcesImpl$3.invoke(ServiceResourcesImpl.java:124)
at
org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:68)
at
org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:68)
at
org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:941)
at
org.apache.tapestry5.ioc.internal.ServiceResourcesImpl.getMappedConfiguration(ServiceResourcesImpl.java:120)
at
org.apache.tapestry5.ioc.internal.AbstractServiceCreator.getMappedConfiguration(AbstractServiceCreator.java:142)
at
org.apache.tapestry5.ioc.internal.AbstractServiceCreator.access$300(AbstractServiceCreator.java:35)
at
org.apache.tapestry5.ioc.internal.AbstractServiceCreator$1.findResource(AbstractServiceCreator.java:107)
at
org.apache.tapestry5.ioc.internal.util.DelegatingInjectionResources.findResource(DelegatingInjectionResources.java:38)
at
org.apache.tapestry5.ioc.internal.util.InternalUtils.calculateInjection(InternalUtils.java:201)
at
org.apache.tapestry5.ioc.internal.util.InternalUtils.access$000(InternalUtils.java:43)
at
org.apache.tapestry5.ioc.internal.util.InternalUtils$2.invoke(InternalUtils.java:256)
at
org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:68)
at
org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:68)
at
org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:941)
at
org.apache.tapestry5.ioc.internal.util.InternalUtils.calculateParameters(InternalUtils.java:260)
at
org.apache.tapestry5.ioc.internal.util.InternalUtils.calculateParametersForMethod(InternalUtils.java:217)
at
org.apache.tapestry5.ioc.internal.ServiceBuilderMethodInvoker.createObject(ServiceBuilderMethodInvoker.java:56)
... 80 more
Caused by: java.lang.RuntimeException: Exception constructing service
'HibernateSessionSource': Error invoking service builder method
org.apache.tapestry5.hibernate.HibernateCoreModule.buildHibernateSessionSource(Logger,
List, RegistryShutdownHub) (at HibernateCoreModule.java:123) (for
service 'HibernateSessionSource'):
org/apache/commons/collections/map/LRUMap
at
org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator.obtainObjectFromCreator(JustInTimeObjectCreator.java:78)
at
org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator.createObject(JustInTimeObjectCreator.java:57)
at
$HibernateSessionSource_12a14ccbe30.delegate($HibernateSessionSource_12a14ccbe30.java)
at
$HibernateSessionSource_12a14ccbe30.getConfiguration($HibernateSessionSource_12a14ccbe30.java)
at
org.apache.tapestry5.hibernate.HibernateModule.contributeValueEncoderSource(HibernateModule.java:89)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.apache.tapestry5.ioc.internal.ContributionDefImpl.invokeMethod(ContributionDefImpl.java:110)
... 108 more
Caused by: org.apache.tapestry5.ioc.internal.OperationException: Error
invoking service builder method
org.apache.tapestry5.hibernate.HibernateCoreModule.buildHibernateSessionSource(Logger,
List, RegistryShutdownHub) (at HibernateCoreModule.java:123) (for
service 'HibernateSessionSource'):
org/apache/commons/collections/map/LRUMap
at
org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:90)
at
org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:68)
at
org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:941)
at
org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator.createObject(OperationTrackingObjectCreator.java:49)
at
org.apache.tapestry5.ioc.internal.SingletonServiceLifecycle.createService(SingletonServiceLifecycle.java:29)
at
org.apache.tapestry5.ioc.internal.LifecycleWrappedServiceCreator.createObject(LifecycleWrappedServiceCreator.java:46)
at
org.apache.tapestry5.ioc.internal.AdvisorStackBuilder.createObject(AdvisorStackBuilder.java:60)
at
org.apache.tapestry5.ioc.internal.InterceptorStackBuilder.createObject(InterceptorStackBuilder.java:52)
at
org.apache.tapestry5.ioc.internal.RecursiveServiceCreationCheckWrapper.createObject(RecursiveServiceCreationCheckWrapper.java:60)
at
org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator$1.invoke(OperationTrackingObjectCreator.java:45)
at
org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:68)
at
org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:68)
at
org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:941)
at
org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator.createObject(OperationTrackingObjectCreator.java:49)
at
org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator.obtainObjectFromCreator(JustInTimeObjectCreator.java:68)
... 117 more
Caused by: java.lang.RuntimeException: Error invoking service builder
method
org.apache.tapestry5.hibernate.HibernateCoreModule.buildHibernateSessionSource(Logger,
List, RegistryShutdownHub) (at HibernateCoreModule.java:123) (for
service 'HibernateSessionSource'):
org/apache/commons/collections/map/LRUMap
at
org.apache.tapestry5.ioc.internal.ServiceBuilderMethodInvoker.createObject(ServiceBuilderMethodInvoker.java:76)
at
org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator$1.invoke(OperationTrackingObjectCreator.java:45)
at
org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:68)
... 131 more
*Caused by: java.lang.NoClassDefFoundError:
org/apache/commons/collections/map/LRUMap*
at org.hibernate.util.SimpleMRUCache.init(SimpleMRUCache.java:71)
at org.hibernate.util.SimpleMRUCache.<init>(SimpleMRUCache.java:55)
at org.hibernate.util.SimpleMRUCache.<init>(SimpleMRUCache.java:50)
at
org.hibernate.engine.query.QueryPlanCache.<init>(QueryPlanCache.java:65)
at
org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:182)
at
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1341)
at
org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
at
org.apache.tapestry5.internal.hibernate.HibernateSessionSourceImpl.<init>(HibernateSessionSourceImpl.java:45)
at
org.apache.tapestry5.hibernate.HibernateCoreModule.buildHibernateSessionSource(HibernateCoreModule.java:123)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.apache.tapestry5.ioc.internal.ServiceBuilderMethodInvoker.createObject(ServiceBuilderMethodInvoker.java:64)
The part that stands out to me is:
**Caused by: java.lang.NoClassDefFoundError:
org/apache/commons/collections/map/LRUMap**
My best guess is that this is a result of the JasperReports 3.7.4
dependency, as I isolated this to only occur when code dependent on
this library is in the application. When I use the Chenillekit-Reports
dependency instead, this exception goes away. A bit interesting...
this exception doesn't actually affect my application since I can use
the Chenillekit-Reports jar, but it seemed worthwhile to mention the
incompatibility.
When I use the ChenilleKit-Reports dependency though, I get the same
exception in my AppModule as ChenilleKitReportsModule from a null in
the buildReportsService method.
Regards,
Rich
Rich wrote:
Hi,
I have to integrate some Jasper reports into a Tapestry web app and I
came across Chenillekit-reports, which seems like it might be a
solution. I'm having a hard time finding any useful documentation
related to it though. Are there any web resources available
explaining implementation or should I just work my way through the
source code? I'm assuming this is the best implementation of
JasperReports into Tapestry at this point in time, but if there are
other options I'm all ears.
Regards,
Rich
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org