如何根据netbean gui中的用户输入生成ireport [英] How to generate an ireport according user input in netbean gui

查看:166
本文介绍了如何根据netbean gui中的用户输入生成ireport的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CREATE TABLE Account(
    account_no int,
    balance real,
    type_code int,
    branch_no int,
    Bcode int,
    customer_no int,

    CONSTRAINT account_pk PRIMARY KEY (account_no),

);

我想在用户提供 type_code(帐户类型)时生成Jasper报告代码) branch_no 作为GUI输入,然后ireport应显示上述帐户表的所有帐户详细信息。

I want to generate a Jasper Report when user gives the type_code(account type code) or branch_no as GUI inputs, then the ireport should display all the account details of above account table.

我不知道怎么做。任何人都可以帮助我吗?

I have no idea how to do this. can anyone help me ?

推荐答案

首先,你没有指定你想要创建的应用程序类型,所以我'我的回答有点笼统。你也没有提到你是否已经设法建立你的第一份报告(我的意思是,没有任何用户输入)。所以,下面我展示了生成JasperReport所需的部分:

First of all you didn't specify the kind of application you want to create, so i'm being a bit general on my response. Also you didn't mention if you've already managed to build your first report (i mean, without taking any user input). So, below i'm showing the needed part for generating a JasperReport:

public void generateReport(ActionEvent actionEvent) throws FileNotFoundException {

JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(PopulateBean.createBeanCollection());
Map parameters = new HashMap();

try {
    InputStream is = new FileInputStream(new File("Source path to template.jrxml"));
    OutputStream os=new FileOutputStream(new File("Resulting report.pdf"));

    JasperDesign jasperDesign = JRXmlLoader.load(is);
    JasperReport jasperReport =
        JasperCompileManager.compileReport(jasperDesign);

    JasperPrint jasperPrint =
        JasperFillManager.fillReport(jasperReport, parameters, ds);

    JasperExportManager.exportReportToPdfStream(jasperPrint, os);
} catch (JRException e) {
      e.printStackTrace();
}

}

此代码应集成到​​您的应用程序中。你要求的部分是:

This code should be integrated into your application. The part you are asking for is:

Map parameters = new HashMap();

您只需将用户插入的输入放入此地图即可。例如,如果你有一个JSF页面,那么你可以获取它的UI组件的值并存储在这个地图中

You have just to put the input inserted by the user into this map. Example, if you have a JSF page, then you can take the value of it's UI component and store in this map

parameters.put("type_code", getTypeCodeUIComponent().getValue());

您将在上面的代码中看到此地图已传递到报告:

You'll see on the code above that this map is passed to the report:

JasperFillManager.fillReport(jasperReport, parameters, ds);

唯一剩下的就是在iReport中编辑报表查询。首先,创建一个与插入地图的名称完全相同的参数(在本例中为type_code。注意,它区分大小写)。其次,您应该使用WHERE子句,根据此参数过滤类型列,请参阅下文:

这里你去一些教程: 1 2

The only thing that remains is to edit your report query, in iReport. First you create a parameter with the exact same name as that inserted into the map (in this example "type_code". Note, it's case sensitive). Second, you should use a WHERE clause where you filter the type column based on this parameter, see below: And here you go some tutorials:1 and 2

希望这些有帮助!

这篇关于如何根据netbean gui中的用户输入生成ireport的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆