2013-09-05 55 views
0

我不知道如何来呈现来自Grails的列表属性,碧玉报告显示Grails的列表属性

我的领域类看起来是这样的:

class Project { 


String name 
String division 
List divisions 

String toString(){ 
    "$name" 
} 


static hasMany = [divisions : Division ] 
... 

和分割域类说到这儿

class Division { 

String name 
String divisionResponsible 
String createDate 

... 

项目控制器看起来像这样

class ProjectController { 


def scaffold = true 

def index = { 
    redirect(action : list) 
} 


def createReport = { 

    def projectreport = Project.getAll([params.project_id]) 
    chain(controller:'jasper',action:'index',model:[data:projectreport],params:params) 

} 

}

我用iReport创建了一个jasper报告,它工作正常。我在列表中添加了字段,并通过访问$ F {name},但我不知道如何添加分区列表。我想要一个包含每行一个元素的列表。

UPDATE JRXML文件添加:

<?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="books" language="groovy" pageWidth="595" pageHeight="842" columnWidth="535" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="589a675d-513d-46ec-9006-3fa969e8706c"> 
<property name="ireport.zoom" value="2.4793388429752063"/> 
<property name="ireport.x" value="193"/> 
<property name="ireport.y" value="397"/> 
<style name="table"> 
    <box> 
     <pen lineWidth="1.0" lineColor="#000000"/> 
    </box> 
</style> 
<style name="table_TH" mode="Opaque" backcolor="#F0F8FF"> 
    <box> 
     <pen lineWidth="0.5" lineColor="#000000"/> 
    </box> 
</style> 
<style name="table_CH" mode="Opaque" backcolor="#BFE1FF"> 
    <box> 
     <pen lineWidth="0.5" lineColor="#000000"/> 
    </box> 
</style> 
<style name="table_TD" mode="Opaque" backcolor="#FFFFFF"> 
    <box> 
     <pen lineWidth="0.5" lineColor="#000000"/> 
    </box> 
</style> 
<subDataset name="Table Dataset 1" uuid="b86e8ec3-65e5-4049-a20a-196817cb20f9"/> 
<subDataset name="dataset1" uuid="92950e66-e6cf-4276-a35e-08a5874a7395"/> 
<subDataset name="dataset2" uuid="8f6281e8-ec37-4c7a-896d-f70ffe464372"/> 
<parameter name="id" class="java.lang.String" isForPrompting="false"> 
    <defaultValueExpression><![CDATA["<parameter error>"]]></defaultValueExpression> 
</parameter> 
<queryString> 
    <![CDATA[]]> 
</queryString> 
<field name="internet" class="java.lang.String"/> 
<field name="projectResponsible" class="java.lang.String"/> 
<field name="name" class="java.lang.String"/> 
<field name="criticality" class="java.lang.String"/> 
<field name="notes" class="java.lang.String"/> 
<field name="id" class="java.lang.String"/> 
<field name="divisions" class="java.lang.String"/> 
<field name="projectStatus" class="java.lang.String"/> 
<group name="Group1"> 
    <groupHeader> 
     <band height="33"> 
      <line> 
       <reportElement uuid="79864a95-d697-467e-bc50-8ef45a45d907" x="-20" y="32" width="595" height="1" forecolor="#666666"/> 
      </line> 
      <staticText> 
       <reportElement uuid="32eb2454-9c31-4af7-b7d2-2f1500d0f0b9" mode="Opaque" x="0" y="12" width="124" height="20" forecolor="#006699" backcolor="#E6E6E6"/> 
       <textElement textAlignment="Center"> 
        <font size="14" isBold="true"/> 
       </textElement> 
       <text><![CDATA[Project status]]></text> 
      </staticText> 
      <textField> 
       <reportElement uuid="f4a48bf5-2347-48d8-90be-48ef1fc765d7" x="124" y="13" width="164" height="20" forecolor="#006699"/> 
       <textElement> 
        <font size="14" isBold="true"/> 
       </textElement> 
       <textFieldExpression><![CDATA[$F{projectStatus}]]></textFieldExpression> 
      </textField> 
     </band> 
    </groupHeader> 
    <groupFooter> 
     <band/> 
    </groupFooter> 
</group> 
<group name="Group3"> 
    <groupFooter> 
     <band/> 
    </groupFooter> 
</group> 
<group name="Group4"> 
    <groupFooter> 
     <band/> 
    </groupFooter> 
</group> 
<background> 
    <band/> 
</background> 
<title> 
    <band height="72"> 
     <frame> 
      <reportElement uuid="d6921c84-754f-47f8-8e1c-ed5296807395" mode="Opaque" x="-20" y="-20" width="595" height="92" backcolor="#FFFFFF"/> 
      <staticText> 
       <reportElement uuid="f9a14771-1465-4f54-ba47-0fa5297df8df" x="20" y="20" width="245" height="33" forecolor="#006699"/> 
       <textElement> 
        <font size="24" isBold="true"/> 
       </textElement> 
       <text><![CDATA[Project Report]]></text> 
      </staticText> 
      <image> 
       <reportElement uuid="3de03b7e-39e1-4b64-bde9-0a663fea3cc6" x="279" y="16" width="306" height="76"/> 
       <imageExpression><![CDATA["C:\\Users\\Guest\\Desktop\\Logo.png"]]></imageExpression> 
      </image> 
     </frame> 
    </band> 
</title> 
<pageHeader> 
    <band height="13"/> 
</pageHeader> 
<columnHeader> 
    <band height="21"> 
     <staticText> 
      <reportElement uuid="f2fa74e2-9914-4bfa-872b-6afb705b016c" mode="Opaque" x="0" y="0" width="124" height="20" forecolor="#006699" backcolor="#E6E6E6"/> 
      <textElement textAlignment="Center"> 
       <font size="14" isBold="true"/> 
      </textElement> 
      <text><![CDATA[Project]]></text> 
     </staticText> 
     <line> 
      <reportElement uuid="c5c5d539-6b26-4467-befe-de4a4adc28fe" x="-20" y="20" width="595" height="1" forecolor="#666666"/> 
     </line> 
     <textField> 
      <reportElement uuid="ff2c3497-9ef4-4546-b1b0-d9e44f8944af" x="124" y="1" width="164" height="20" forecolor="#006699"/> 
      <textElement> 
       <font size="14" isBold="true"/> 
      </textElement> 
      <textFieldExpression><![CDATA[$F{name}]]></textFieldExpression> 
     </textField> 
    </band> 
</columnHeader> 
<detail> 
    <band height="194"> 
     <staticText> 
      <reportElement uuid="eb8ac25a-7d64-41f8-9e72-04103fd7d9c1" mode="Opaque" x="0" y="23" width="124" height="20" forecolor="#006699" backcolor="#E3E3E3"/> 
      <textElement> 
       <font size="14" isBold="true"/> 
      </textElement> 
      <text><![CDATA[Project Resonsible]]></text> 
     </staticText> 
     <textField> 
      <reportElement uuid="aee33b53-790c-4749-ba9e-b83a7752af74" mode="Opaque" x="124" y="23" width="164" height="20" forecolor="#006699" backcolor="#E3E3E3"/> 
      <textElement> 
       <font size="12" isBold="true"/> 
      </textElement> 
      <textFieldExpression><![CDATA[$F{projectResponsible}]]></textFieldExpression> 
     </textField> 
     <staticText> 
      <reportElement uuid="42af2015-ef1f-4f81-996f-238030838ad2" mode="Opaque" x="0" y="43" width="124" height="20" forecolor="#006699" backcolor="#FFFFFF"/> 
      <textElement> 
       <font size="14" isBold="true"/> 
      </textElement> 
      <text><![CDATA[Criticality]]></text> 
     </staticText> 
     <textField> 
      <reportElement uuid="7cf09291-11fc-4cff-a7b4-a07722c8953b" x="124" y="43" width="164" height="19" forecolor="#006699"/> 
      <textElement> 
       <font size="12" isBold="true"/> 
      </textElement> 
      <textFieldExpression><![CDATA[$F{criticality}]]></textFieldExpression> 
     </textField> 
     <staticText> 
      <reportElement uuid="8c4c1f4e-a5ac-4600-af3b-6a2f74b17b5f" mode="Opaque" x="0" y="62" width="124" height="20" forecolor="#006699" backcolor="#E3E3E3"/> 
      <textElement> 
       <font size="14" isBold="true"/> 
      </textElement> 
      <text><![CDATA[Notes]]></text> 
     </staticText> 
     <textField> 
      <reportElement uuid="4d7b1e31-33a0-4c5b-9576-9ca9221ab2f3" mode="Opaque" x="124" y="62" width="164" height="20" forecolor="#006699" backcolor="#E3E3E3"/> 
      <textElement> 
       <font size="12" isBold="true"/> 
      </textElement> 
      <textFieldExpression><![CDATA[$F{notes}]]></textFieldExpression> 
     </textField> 
     <line> 
      <reportElement uuid="9721dd86-1744-40eb-a378-87e8b00acb06" x="0" y="93" width="555" height="1"/> 
     </line> 
     <staticText> 
      <reportElement uuid="3622cfdb-db15-4fe6-8d9c-30d6bd51a4df" mode="Opaque" x="0" y="94" width="555" height="20" forecolor="#006699" backcolor="#E6E6E6"/> 
      <textElement> 
       <font size="14" isBold="true"/> 
      </textElement> 
      <text><![CDATA[Divisions]]></text> 
     </staticText> 
    </band> 
</detail> 
<columnFooter> 
    <band/> 
</columnFooter> 
<pageFooter> 
    <band height="17"> 
     <textField> 
      <reportElement uuid="e963f52c-256f-42ce-bf06-5abeaae6532a" mode="Opaque" x="0" y="4" width="515" height="13" backcolor="#E6E6E6"/> 
      <textElement textAlignment="Right"/> 
      <textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression> 
     </textField> 
     <textField evaluationTime="Report"> 
      <reportElement uuid="4aa95590-464b-4759-9865-201021b8d77c" mode="Opaque" x="515" y="4" width="40" height="13" backcolor="#E6E6E6"/> 
      <textElement/> 
      <textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression> 
     </textField> 
     <textField pattern="EEEEE dd MMMMM yyyy"> 
      <reportElement uuid="f5f6139c-b44e-4354-8216-29550ebbcdd0" x="0" y="4" width="100" height="13"/> 
      <textElement/> 
      <textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression> 
     </textField> 
    </band> 
</pageFooter> 
<summary> 
    <band/> 
</summary> 

更新2:

我设法访问由在碧玉报告

使用以下变量列表中的元素
$F{divisions.[0].name} 
$F{divisions.[1].name} 

现在的问题是,这在实际报表中并不真正可用,因为我不知道列表中有多少个元素。

有没有办法在jasper报表中遍历列表元素?

+0

你能后的* JRXML *文件? –

回答

0

您是否尝试过使用

<printWhenExpression><![CDATA[$F{data}.get(0) != null]]></printWhenExpression> 
<textFieldExpression><![CDATA[$F{data}.get(0).name]]></textFieldExpression> 

的部门:

<printWhenExpression><![CDATA[$F{data}.get(0).divisions != null && $F{data}.get(0).divisions.get(0) != null]]></printWhenExpression> 
<textFieldExpression><![CDATA[$F{data}.get(0).divisions.get(0).name]]></textFieldExpression> 
+0

嗯,这不是真的工作。 如果我添加下面我得到一个错误: \t \t \t \t \t \t \t \t \t \t \t \t <![CDATA [$ F {}划分获得(0)。名称]]> \t \t \t 添加printWhenExpression也不起作用。我是否必须准确地说出这一点? – mbs