struts-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brice Roncace (JIRA)" <>
Subject [jira] [Commented] (WW-3698) jasperreports plugin's ValueStackDataSource converts field values in ValueStackDataSource even when it's not wanted
Date Mon, 07 Oct 2013 16:32:45 GMT


Brice Roncace commented on WW-3698:

This fix caused my jasperreports to break migrating from struts-2.3.4 to struts-

For example, I have a jasperreport pulling in fields from a simple "datasource" interface
type I've made available on my action:

public interface EmployeeDataSource {
  public Employee getEmployee();
  public List<Training> getTraining();
  public List<Employment> getEmployment();
  public List<Certificate> getCertificates();

The report defines a *training* field which is passed to a subreport as its datasource.  This
field type was set to {{java.lang.Object}}, but this does not work with the changes introduced
in this patch (also won't work for java.util.List).  I really do want this list to be decorated
as a {{JRDataSource}} not used directly.  I tried to explicitly set the type of the *training*
field to {{net.sf.jasperreports.engine.JRDataSource}} but no luck.

Here's the exception:
javax.servlet.ServletException: Error evaluating expression : Source text : $F{training}
Caused by: java.lang.ClassCastException: java.util.ArrayList cannot be cast to net.sf.jasperreports.engine.JRDataSource

How do I alleviate this issue?  Thank you!

> jasperreports plugin's ValueStackDataSource converts field values in ValueStackDataSource
even when it's not wanted
> -------------------------------------------------------------------------------------------------------------------
>                 Key: WW-3698
>                 URL:
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Plugin - JasperReports
>    Affects Versions:
>         Environment: Tomcat 7 application server, Jasperreports 4.1.1
>            Reporter: Dario Tortola
>            Assignee: Lukasz Lenart
>            Priority: Minor
>              Labels: patch
>             Fix For: 2.3.12
>   Original Estimate: 20m
>  Remaining Estimate: 20m
> Report A with Subreport B
> Subreport B's datasource is a java.util.List field of Report A's datasource's elements
> org.apache.struts2.views.jasperreports.ValueStackDataSource.getFieldValue, after locating
the value, if org.apache.struts2.util.MakeIterator.isIterable(value) instead of value a new
ValueStackDataSource over value is returned.
> Since ValueStackDataSource is not a java.util.List, a javax.servlet.ServletException
is thrown when the returned ValueStackDataSource fails to be cast to List
> To avoid such unwanted conversion it's enough to change this code on ValueStackDataSource.getFieldValue
> {code:java}
> if (MakeIterator.isIterable(value)) {
>    return new ValueStackDataSource(this.valueStack, expression);
> } else {
>    return value;
> }
> {code}
> replace (MakeIterator.isIterable(value)) with (!field.getValueClass().isInstance(value)
&& MakeIterator.isIterable(value)) for the new ValueStackDataSource to be returned
only if the value is not already what the field asks for

This message was sent by Atlassian JIRA

View raw message