JasperReports: access custom data source

I am quite new to JasperReports and I need to create a report from a custom data source. For this I implemented the JRDataSource interface, with the two methods:

public class FacultyStudentsDS implements JRDataSource {

    @Override
    public Object getFieldValue(JRField field) throws JRException {
        ...
    }

    @Override
    public boolean next() throws JRException {
        ...
    }
}

then I try to create a PDF document, this way:

pdf = JasperRunManager.runReportToPdf(reportFile.getAbsolutePath(),
new HashMap(), studentsDS);

My problem is that I do not know how to access the data I pass to the report. I have no idea what to write in the .jrxml file. How do I access the studentsDS variable that I pass to the report, in the .jrxml file?

Answers


You need to have <detail> band. Then within that band you can access fields from the data source by using something like the following:

<textFieldExpression class="java.lang.String"><![CDATA[$F{dataSourceField}]]></textFieldExpression>

Depending on your needs, you might not need to create your own custom data source. By wrapping a Collection of Java beans in a JRBeanCollectionDataSource you can access the properties of the Java beans in that collection using the above $F{ syntax.


Need Your Help

Rails3/Devise: undefined method new_application_user_session_path

ruby-on-rails ruby-on-rails-3 ldap devise

Following the README documentation, I installed Devise into an existing Rails 3 application. However, it doesn't seem to work. When I try to access one of my controllers that have before_filter

concordance file in python

python

The task is to write a program which prompts for a filename and then produces a concordance of that file.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.