Jump to content

How to print text without dataset?


andber

Recommended Posts

I am needing print only a attributes from a object without DB connection and dataset.

I have for example the object "Student" and I need print the following attributes:
Name
Last Name
Year

I am using the following source code:

        try {
            String strFile;
            Map Data= new HashMap();

            Data.put("Name", "Pepe");
            Data.put("Lastname", "Perez");
            Data.put("Year", "2010");
 

            strFile = "StudentReport.jasper";

            JasperReport masterReport = null;
            masterReport = (JasperReport) JRLoader.loadObject(strFile);

            JasperPrint jp = JasperFillManager.fillReport(masterReport, Data, new JREmptyDataSource());

            JasperViewer view = new JasperViewer(jp,false);

            view.setTitle("title");
            view.setVisible(true);
           

        } catch (JRException ex) {
            Logger.getLogger(ImpApp.class.getName()).log(Level.SEVERE, null, ex);
        }

This code print a withe paper, why? I need this print the data:
Pepe
Perez
2010

How I can do that?

Thanks in advance,
Andrés.

Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Take a look at this post:

http://jasperforge.org/plugins/espforum/view.php?group_id=102&forumid=103&topicid=76965&topid=77042#77042

Maybe what you really need is a JRBeanDataSource. Very simple to use. You pass a collection of your own beans to the reports as a datasource, so the fileds of the report are your bean's fields (whth getter and setters).

 

hope it helps

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...