2009-05-29 2 views
1

내 재 스퍼 보고서 작성 문제가 struts2 인 Im 작성 중입니다.JasperReport struts2에서 사용하는 문제 - 최종 PDF 파일에 null이 표시되는 경우

struts.xml이 포함되어 있습니다 :

<action name="myJasperTest1" class="temp.JasperAction1"> 
    <result name="success" type="jasper"> 
     <param name="location">/jasper/our_compiled_template.jasper</param> 
     <param name="dataSource">myList</param> 
     <param name="format">PDF</param> 
    </result> 
</action> 

내 JasperAction1가 포함

import java.util.ArrayList; 
import java.util.List; 
import java.io.FileInputStream; 
import com.opensymphony.xwork2.ActionSupport; 
import com.sufalam.business.model.util.LegacyJasperInputStream; 
import com.sufalam.business.finance.model.bean.Account; 
import net.sf.jasperreports.engine.JasperCompileManager; 
import net.sf.jasperreports.engine.design.JasperDesign; 
import net.sf.jasperreports.engine.xml.JRXmlLoader; 

public class JasperAction1 extends ActionSupport { 

    /** List to use as our JasperReports dataSource. */ 
    private List<Account> myList; 

    public String execute() throws Exception { 

     // Create some imaginary persons. 
     Account a1 = new Account(); 
     Account a2 = new Account(); 

     a1.setId(77); 
     a1.setName("aaa"); 
     a2.setId(88); 
     a2.setName("bbb"); 
     // Store people in our dataSource list (normally would come from database). 
     myList = new ArrayList<Account>(); 
     myList.add(a1); 
     myList.add(a2); 

     // Normally we would provide a pre-compiled .jrxml file 
     // or check to make sure we don't compile on every request. 
     try { 
      JasperDesign design = JRXmlLoader.load(
        new LegacyJasperInputStream(new FileInputStream("F://backup//report2.jrxml"))); 

      JasperCompileManager.compileReportToFile(design, "F://backup//our_compiled_template1.jasper"); 
     } catch (Exception e) { 
      e.printStackTrace(); 
      return ERROR; 
     } 

     return SUCCESS; 
    } 

    public List<Account> getMyList() { 
     return myList; 
    } 
} 

내가 의 iReport 플러그인 의 넷빈즈을 사용하고 다음은 내가 실행하기 위해 노력하고있어 코드 .jrxml 파일을 생성하십시오. 내가 PDF 형식으로 출력 다음은 나에게주는이 작업 클래스를 실행할 때

<?xml version="1.0" encoding="UTF-8"?> 
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="null" pageWidth="595" pageHeight="842" columnWidth="535" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20"> 
    <queryString language="SQL"> 
      <![CDATA[SELECT 
     account_master."name" AS account_master_name, 
     account_master."id" AS account_master_id 
    FROM 
     "public"."account_master" account_master]]> 
    </queryString> 
    <field name="account_master_name" class="java.lang.String"/> 
    <field name="account_master_id" class="java.lang.Integer"/> 
    <title> 
     <band height="58"> 
      <line> 
       <reportElement x="0" y="8" width="555" height="1"/> 
      </line> 
      <line> 
       <reportElement positionType="FixRelativeToBottom" x="0" y="51" width="555" height="1"/> 
      </line> 
      <staticText> 
       <reportElement x="65" y="13" width="424" height="35"/> 
       <textElement textAlignment="Center"> 
        <font size="26" isBold="true"/> 
       </textElement> 
       <text><![CDATA[Classic template]]> 
       </text> 
      </staticText> 
     </band> 
    </title> 
    <detail> 
     <band height="40"> 
      <staticText> 
       <reportElement x="0" y="0" width="139" height="20"/> 
       <textElement> 
        <font size="12"/> 
       </textElement> 
       <text><![CDATA[account_master_name]]> 
       </text> 
      </staticText> 
      <textField> 
       <reportElement x="139" y="0" width="416" height="20"/> 
       <textElement> 
        <font size="12"/> 
       </textElement> 
       <textFieldExpression class="java.lang.String"><![CDATA[$F{account_master_name}]]> 
       </textFieldExpression> 
      </textField> 
      <staticText> 
       <reportElement x="0" y="20" width="139" height="20"/> 
       <textElement> 
        <font size="12"/> 
       </textElement> 
       <text><![CDATA[account_master_id]]> 
       </text> 
      </staticText> 
      <textField> 
       <reportElement x="139" y="20" width="416" height="20"/> 
       <textElement> 
        <font size="12"/> 
       </textElement> 
       <textFieldExpression class="java.lang.Integer"><![CDATA[$F{account_master_id}]]> 
       </textFieldExpression> 
      </textField> 
     </band> 
    </detail> 
    <pageFooter> 
     <band height="26"> 
      <textField evaluationTime="Report" pattern="" isBlankWhenNull="false"> 
       <reportElement key="textField" x="516" y="6" width="36" height="19" forecolor="#000000" backcolor="#FFFFFF"/> 
       <box> 
        <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> 
        <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> 
        <bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> 
        <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> 
       </box> 
       <textElement> 
        <font size="10"/> 
       </textElement> 
       <textFieldExpression class="java.lang.String"><![CDATA["" + $V{PAGE_NUMBER}]]> 
       </textFieldExpression> 
      </textField> 
      <textField pattern="" isBlankWhenNull="false"> 
       <reportElement key="textField" x="342" y="6" width="170" height="19" forecolor="#000000" backcolor="#FFFFFF"/> 
       <box> 
        <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> 
        <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> 
        <bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> 
        <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> 
       </box> 
       <textElement textAlignment="Right"> 
        <font size="10"/> 
       </textElement> 
       <textFieldExpression class="java.lang.String"><![CDATA["Page " + $V{PAGE_NUMBER} + " of "]]> 
       </textFieldExpression> 
      </textField> 
      <textField pattern="" isBlankWhenNull="false"> 
       <reportElement key="textField" x="1" y="6" width="209" height="19" forecolor="#000000" backcolor="#FFFFFF"/> 
       <box> 
        <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> 
        <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> 
        <bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> 
        <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/> 
       </box> 
       <textElement> 
        <font size="10"/> 
       </textElement> 
       <textFieldExpression class="java.util.Date"><![CDATA[new Date()]]> 
       </textFieldExpression> 
      </textField> 
     </band> 
    </pageFooter> 
</jasperReport> 

가 지금 직면하고있어 문제가 : alt text의 iReport 마법사 내 our_jasper_template.jrxml 파일을 사용하여 내 페이지를 디자인 한 후 다음 코드 포함

답변

1

.jrxml 파일에서 쿼리 문자열 부분을 삭제하고 계정 클래스의 변수 이름으로 필드 이름을 변경하십시오.

0

최종 해결책이 없을 수도 있지만 이상한 것처럼 보이는 세부 사항이 있습니다. account_master_nameaccount_master_id 필드는 실제로 계정 클래스의 속성 이름과 정렬되지 않습니다. idname이 아니어야합니까? 이상한 점은 보고서를 채울 때 오류가 발생해야한다는 것입니다 ...

저는 Struts에 익숙하지 않지만 영향을 줄 수는 없습니다.

+0

나중에하지만 필드 이름으로 ID 및 이름을 변경하려고했습니다. 하지만 여전히 보고서를 작성하는 동안 오류가 아니라 결과로 null 값을 얻고있다. DEBUG는 나를 채우는 것을 보여줍니다 : null은 오류가 아닙니다 ... 당신의 의견이 있습니까? – Nirmal

관련 문제