English 中文(简体)
JSF and jasper example
原标题:JSF and jasper example

I am new to JSF, I want to integrate JSF with Jasper report. I am generating custom report from server side, that report should display into the UI using JSF components. How to do that? Could you please provide the JSF and Jasper Report Simple Program and required libraries.

问题回答

假设你再谈一下JasperReports的超文本报告,你最好不要忘记在现阶段讨论共同基金的范围,因为这与JasperReports无关。 反过来,共同基金也可以用“第三党”的超文本做任何明智的事情。 仅添加一个“超文本编码”和“超文本”;要素,加入“数字代码”网页,其<代码><>/代码>在<代码>的URL上点。 HttpServlet,根据请求参数或途径,将JasperReports理想的超文本报告退回,而你则能够动态地利用EL。 例如:

<iframe width="600" height="400" src="reportservlet?id=${bean.someid}"></iframe>

<url-pattern >后面的HttpServlet 仅可根据其文件/指南援引JasperReports, 并得上<>InputStream,并写上>。 HttpServletResponse连同一套正确的回复头,至少是Content-Type

BalusC suggestion seems good in case you want HTML reports. Here is my answer in case you wanted any other format (say PDF)

Ajax要求“准备”报告,然后将报告存放在某个地方,然后将新创建的报告索引归还给你。

反应要么成功,要么失败。 如果成功,你会打开一个有假设的URL的新窗口,并将PDF文件提交给它(使用你拥有的ID)。

您可从以下链接下载J.J.

rel=“nofollow” http://www.java2s.com/Code/Jar/d/Downloaddynamicreportscore310jar.htm

或 如果你使用ven子,那么你在om子档案中只增加以下依赖物。

<dependency>
    <groupId>net.sourceforge.dynamicreports</groupId>
    <artifactId>dynamicreports-core</artifactId>
    <version>3.1.3</version>
</dependency>

页: 1

<h:commandLink id="summary_jasper" actionListener="#{workReportBean.prepareJasperReport()}">
      <p:graphicImage name="/images/jasper.png"  title="Jasper"/>
</h:commandLink>

Managed Bean //Just provide DB_NAME, CREDENTIALS and TABLE_NAME, JASPER report will be created for you

public void prepareJasperReport(){
    Map<String, String> columnNameNTypeMap = new HashMap<String, String>();
    Connection connection = null;
    try {
        Class.forName("com.mysql.jdbc.Driver");
        connection = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/DB_NAME", "USER", "PASSWORD");
        ResultSet rsColumns = null;
        DatabaseMetaData meta = connection.getMetaData();
        rsColumns = meta.getColumns(null, null, "TABLE_NAME", null);
        while (rsColumns.next()) {
            columnNameNTypeMap.put(rsColumns.getString("COLUMN_NAME"), rsColumns.getString("TYPE_NAME"));
        }} catch (SQLException e) {
        e.printStackTrace();
        return;
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
        return;
    }

    // a new report
    JasperReportBuilder report = DynamicReports.report();
    // populating new report with TABLE object
    report.setDataSource("select * from TABLE_NAME;", connection);
    // creating COLUMNS // add extra datatypes if your table have ex. long, float etc
    for (Map.Entry<String, String> entry : columnNameNTypeMap.entrySet()){
        if(entry.getValue().equalsIgnoreCase("int")){
            report.columns(Columns.column(entry.getKey(), entry.getKey(), DataTypes.integerType()));
        }else if(entry.getValue().equalsIgnoreCase("varchar")){
            report.columns(Columns.column(entry.getKey(), entry.getKey(), DataTypes.stringType()));
        }else if(entry.getValue().equalsIgnoreCase("bit")){
            report.columns(Columns.column(entry.getKey(), entry.getKey(), DataTypes.booleanType()));
        }else if(entry.getValue().equalsIgnoreCase("datetime") || entry.getValue().equalsIgnoreCase("date")){
            report.columns(Columns.column(entry.getKey(), entry.getKey(), DataTypes.dateType()));
        }

    }

    report.title(Components.text("Summary Report").setHeight(40)
            .setStyle(DynamicReports.stl.style()
            .setBold(true).setFontSize(16).setForegroundColor(Color.BLUE)
            .setAlignment(HorizontalAlignment.CENTER, VerticalAlignment.MIDDLE)));

    report.setColumnTitleStyle(DynamicReports.stl.style().setBold(true));
    report.setColumnStyle(DynamicReports.stl.style().setHorizontalAlignment(HorizontalAlignment.LEFT));
    report.setHighlightDetailEvenRows(true);
    report.pageFooter(Components.pageXofY());

    try {
        // show the report
        report.show(false);
        // export the report to a pdf file
        //report.toPdf(new FileOutputStream("d://report.pdf"));
    } catch (DRException e) {
        e.printStackTrace();
    } /*catch (FileNotFoundException e) {
        e.printStackTrace();
    }*/

}




相关问题
JSF a4j:support with h:selectManyCheckbox

I m having trouble with a JSF selectManyCheckbox and A4J support. The purpose is to run some action when a checkbox is selected. This works perfectly in Firefox. Yet, when testing in any IE (ie6 / ie7 ...

Mojarra for JSF Encoding

Can anyone teach me how to use mojarra to encode my JSF files. I downloaded mojarra and expected some kind of jar but what i had downloaded was a folder of files i don t know what to do with

如何拦截要求终止?

在共同基金中,如果用户要求终止,就需要采取一些行动。 我需要某种拦截器,但我不知道如何这样做。 我需要帮助。 增 编

ICEFaces inputFile getting the file content without upload

Is there any way of just getting the content of the browsed file without any upload/file transfer operations? I currently use ICEFaces inputFile component but I do not need the default uploading ...

Weird behaviour of h:commandLink action (MethodExpression)

I have two JSPs where I am displaying some info from database in a h:dataTable. One of them is showing all the info, and one of them user specifically. I have showXML.jsp that shows the "XML" column ...

How to correctly use ResultSet with h:dataTable

The problem is, that after displaying the ResultSet with <h:dataTable>, the connection is left open. If I close it, it closes the ResultSet too. I m thinking about copying the ResultSet data ...

热门标签