Jump to content
We've recently updated our Privacy Statement, available here ×
  • Using Tables with Domains in Jaspersoft Studio


    ilona
    • Features: Domains, JasperReports Server, Parameters Version: v5.5 Product: Jaspersoft® Studio

    This article contains step-by-step instructions for using a domain in subdatasets which can then be used then to populate tables, charts, lists, and maps, as well as in subreports.

    The Domains query executer (which works only for reports executed inside JasperReports Server), needs the following two parameters:

    • slSchema
    • slFactory

    Even if these parameters are not declared in a report, if a report unit uses a Domain as datasource, they are populated by the report execution service. Thus, in a typical domain-based report, you don't declare any special parameter. You just use a domain query, select your fields, then publish the report as report unit on the sever configuring it to use a domain datasource.

    In effect, declaring parameters is not mandatory in JasperReports. A parameter must be declared only if used in expressions, otherwise it remains available for other parameter consumers, like the domain query executer. Other parameters for which JasperReports servers set a value when it executes a report are LoggedInUser and LoggedInUsername.

    Two things to keep in mind:

    1. Since the main dataset does not need to contain a query if you use on in the table dataset,, set your report to display all bands no details when there is no data. (You can set that in a check box in the report definition).
    2. When working with subreports, all you have to do is to pass the parameters to the subreport. This means, like you do in the dataset run with a sub-dataset, you declare all the parameters in the subreport and use the subreport parameters of the subreport element to set parameter expressions.

    When using a domain query with sub-datasets, you must provide slSchema and slFactory. To do so:

    1. Declare the following parameters in the main report:

      • slSchema (type java.lang.Object)
      • slFactory (type java.lang.Object)
      • LoggedInUser (type java.lang.Object) optional
      • LoggedInUsername (type java.lang.String) optional

      <parameter name="slSchema" class="java.lang.Object"/>
      <parameter name="slFactory" class="java.lang.Object"/>
      <parameter name="LoggedInUser" class="java.lang.Object"/>
      <parameter name="LoggedInUsername" class="java.lang.String"/>
      

      domain-based1.png.9a3d156d9ff0c86220ffa41ee588636a.png

    2. Declare the same two parameters in the sub-dataset.

      domain-based2.png.b2d5e4702c98da5d0b0abdc9d9aed069.png

    3. In the dataset run of the element with which you are working (table, list, chart, etc...), set the value of the parameters slSchema to $P{slSchema} and slFactory to $P{slFactory}.

      domain-based3.png.e97f544b9f6fee775bf55721a997727a.png

      Using this procedure, we pass through to the sub-dataset what JasperReports Server provides automatically to the main dataset.

    Here is sample JRXML that shows a domain-based report that prints a table. You can publish it as a report unit on JasperReports Server; it uses the simple domain.

    <?xml version="1.0" encoding="UTF-8"?>
    <!-- Created with Jaspersoft Studio version last-->
    <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="domain_based_report" pageWidth="595" pageHeight="842"
                  whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20"
                  rightMargin="20" topMargin="20" bottomMargin="20"
                  uuid="69afd846-afc1-4020-aa29-20159af26429">
        <property name="com.jaspersoft.studio.data.defaultdataadapter" value="Demo XML Route"/>
        <property name="ireport.jasperserver.url" value="http://localhost:8080/jasperserver-pro/"/>
        <property name="ireport.domainUri" value="/Domains/Simple_Domain"/>
        <property name="ireport.jasperserver.report.resource" value="/reports/domain_based_report_files/main_jrxml"/>
        <property name="ireport.jasperserver.reportUnit" value="/reports/domain_based_report"/>
        <style name="Table_TH" mode="Opaque" backcolor="#F0F8FF">
            <box>
                <pen lineWidth="0.5" lineColor="#000000"/>
                <topPen lineWidth="0.5" lineColor="#000000"/>
                <leftPen lineWidth="0.5" lineColor="#000000"/>
                <bottomPen lineWidth="0.5" lineColor="#000000"/>
                <rightPen lineWidth="0.5" lineColor="#000000"/>
            </box>
        </style>
        <style name="Table_CH" mode="Opaque" backcolor="#BFE1FF">
            <box>
                <pen lineWidth="0.5" lineColor="#000000"/>
                <topPen lineWidth="0.5" lineColor="#000000"/>
                <leftPen lineWidth="0.5" lineColor="#000000"/>
                <bottomPen lineWidth="0.5" lineColor="#000000"/>
                <rightPen lineWidth="0.5" lineColor="#000000"/>
            </box>
        </style>
        <style name="Table_TD" mode="Opaque" backcolor="#FFFFFF">
            <box>
                <pen lineWidth="0.5" lineColor="#000000"/>
                <topPen lineWidth="0.5" lineColor="#000000"/>
                <leftPen lineWidth="0.5" lineColor="#000000"/>
                <bottomPen lineWidth="0.5" lineColor="#000000"/>
                <rightPen lineWidth="0.5" lineColor="#000000"/>
            </box>
        </style>
        <subDataset name="Dataset1" uuid="e56938cc-3bf8-453a-b319-0677da3f3917">
            <property name="ireport.jasperserver.url" value="http://localhost:8080/jasperserver-pro/"/>
            <property name="ireport.domainUri" value="/Domains/Simple_Domain"/>
            <parameter name="slSchema" class="java.lang.Object"/>
            <parameter name="LoggedInUser" class="java.lang.Object"/>
            <parameter name="slFactory" class="java.lang.Object"/>
            <parameter name="LoggedInUsername" class="java.lang.String"/>
            <queryString language="domain">
                <![CDATA[<query>
        <queryFields>
            <queryField id="newSet1.billing_address_state"/>
            <queryField id="newSet1.billing_address_city"/>
            <queryField id="newSet1.name"/>
        </queryFields>
    </query>]]>
            </queryString>
            <field name="newSet1.billing_address_state" class="java.lang.String">
                <fieldDescription><![CDATA[Account State]]></fieldDescription>
            </field>
            <field name="newSet1.billing_address_city" class="java.lang.String">
                <fieldDescription><![CDATA[Account City]]></fieldDescription>
            </field>
            <field name="newSet1.name" class="java.lang.String">
                <fieldDescription><![CDATA[Account Name]]></fieldDescription>
            </field>
        </subDataset>
        <parameter name="LoggedInUser" class="java.lang.Object"/>
        <parameter name="LoggedInUsername" class="java.lang.String"/>
        <parameter name="slSchema" class="java.lang.Object"/>
        <parameter name="slFactory" class="java.lang.Object"/>
        <queryString>
            <![CDATA[]]>
        </queryString>
        <background>
            <band splitType="Stretch"/>
        </background>
        <title>
            <band height="221" splitType="Stretch">
                <textField>
                    <reportElement x="0" y="20" width="554" height="30" uuid="95094b04-86dd-47fa-9ac0-60fb3b4a6b40"/>
                    <textFieldExpression><![CDATA[$P{LoggedInUser}]]></textFieldExpression>
                </textField>
                <textField>
                    <reportElement x="1" y="62" width="551" height="30" uuid="ee7e96be-8a1b-4508-ba63-79ec31cf9255"/>
                    <textFieldExpression><![CDATA[$P{LoggedInUsername}]]></textFieldExpression>
                </textField>
                <textField>
                    <reportElement x="1" y="112" width="551" height="30" uuid="adb03abc-0c7b-48ce-bdda-177323fcf30a"/>
                    <textFieldExpression><![CDATA[$P{slSchema}]]></textFieldExpression>
                </textField>
                <textField>
                    <reportElement x="0" y="172" width="551" height="30" uuid="073883c5-cc61-48a2-bfff-ab6e2a03b920"/>
                    <textFieldExpression><![CDATA[$P{slFactory}]]></textFieldExpression>
                </textField>
            </band>
        </title>
        <pageHeader>  <band splitType="Stretch"/></pageHeader>
        <columnHeader><band splitType="Stretch"/></columnHeader>
        <detail>      <band splitType="Stretch"/></detail>
        <columnFooter><band splitType="Stretch"/></columnFooter>
        <pageFooter>  <band splitType="Stretch"/></pageFooter>
        <summary>
            <band height="484" splitType="Stretch">
                <componentElement>
                    <reportElement x="1" y="0" width="550" height="484" uuid="46aa5671-36a3-417c-b474-5c4f96d2983f"/>
                    <jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components"
                              xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components
                                                  http://jasperreports.sourceforge.net/xsd/components.xsd">
                        <datasetRun subDataset="Dataset1" uuid="7581c62c-09f2-45e8-bd7b-2ae5efdafc34">
                            <datasetParameter name="slFactory">
                                <datasetParameterExpression><![CDATA[$P{slFactory}]]></datasetParameterExpression>
                            </datasetParameter>
                            <datasetParameter name="slSchema">
                                <datasetParameterExpression><![CDATA[$P{slSchema}]]></datasetParameterExpression>
                            </datasetParameter>
                            <datasetParameter name="LoggedInUser">
                                <datasetParameterExpression>
                                    <![CDATA[$P{LoggedInUser}]]>
                                </datasetParameterExpression>
                            </datasetParameter>
                            <datasetParameter name="LoggedInUsername">
                                <datasetParameterExpression>
                                    <![CDATA[$P{LoggedInUsername}]]>
                                </datasetParameterExpression>
                            </datasetParameter>
                        </datasetRun>
                        <jr:column width="66" uuid="3c9e396b-fcc9-4e3c-83da-5a2f601e64bb">
                            <jr:tableHeader style="Table_TH" height="30"/>
                            <jr:tableFooter style="Table_TH" height="30"/>
                            <jr:columnHeader style="Table_CH" height="30">
                                <staticText>
                                    <reportElement x="0" y="0" width="66" height="30"
                                                   uuid="ee468638-b680-4580-b5be-1f6ead3883a1"/>
                                    <text><![CDATA[newSet1.billing_address_state]]></text>
                                </staticText>
                            </jr:columnHeader>
                            <jr:columnFooter style="Table_CH" height="30"/>
                            <jr:detailCell style="Table_TD" height="30">
                                <textField>
                                    <reportElement x="0" y="0" width="66" height="30"
                                                   uuid="63cb6166-f49c-4b7f-908d-6d7675ad6673"/>
                                    <textFieldExpression>
                                        <![CDATA[$F{newSet1.billing_address_state}]]>
                                    </textFieldExpression>
                                </textField>
                            </jr:detailCell>
                        </jr:column>
                        <jr:column width="66" uuid="fa2a8fb7-cb3b-4102-bcec-686a3d3a2d2d">
                            <jr:tableHeader style="Table_TH" height="30"/>
                            <jr:tableFooter style="Table_TH" height="30"/>
                            <jr:columnHeader style="Table_CH" height="30">
                                <staticText>
                                  <reportElement x="0" y="0" width="66" height="30"
                                                 uuid="be01be07-64dd-4ccd-ac60-b2dbb0569625"/>
                                    <text><![CDATA[newSet1.billing_address_city]]></text>
                                </staticText>
                            </jr:columnHeader>
                            <jr:columnFooter style="Table_CH" height="30"/>
                            <jr:detailCell style="Table_TD" height="30">
                                <textField>
                                    <reportElement x="0" y="0" width="66" height="30"
                                                   uuid="1010aa1c-b6fc-41fc-9826-ff47ce146288"/>
                                    <textFieldExpression>
                                        <![CDATA[$F{newSet1.billing_address_city}]]>
                                    </textFieldExpression>
                                </textField>
                            </jr:detailCell>
                        </jr:column>
                        <jr:column width="66" uuid="1ff372d0-396a-4100-a0ca-f1da70822f00">
                            <jr:tableHeader style="Table_TH" height="30"/>
                            <jr:tableFooter style="Table_TH" height="30"/>
                            <jr:columnHeader style="Table_CH" height="30">
                                <staticText>
                                  <reportElement x="0" y="0" width="66" height="30"
                                                 uuid="d602061b-a8ca-42b1-8d8b-4c5a7f58a4da"/>
                                  <text><![CDATA[newSet1.name]]></text>
                                </staticText>
                            </jr:columnHeader>
                            <jr:columnFooter style="Table_CH" height="30"/>
                            <jr:detailCell style="Table_TD" height="30">
                                <textField>
                                  <reportElement x="0" y="0" width="66" height="30"
                                                 uuid="ad6962e7-cd3d-4978-95eb-da4da1e65165"/>
                                    <textFieldExpression>
                                        <![CDATA[$F{newSet1.name}]]>
                                    </textFieldExpression>
                                </textField>
                            </jr:detailCell>
                        </jr:column>
                    </jr:table>
                </componentElement>
            </band>
        </summary>
    </jasperReport>
    
    

    User Feedback

    Recommended Comments

    There are no comments to display.



    Guest
    This is now closed for further comments

×
×
  • Create New...