4

I am working on a grails project that use jasper plugin for downloading a document in pdf and doc format.

I have several jasper subreports and using these subreports in dynamic jasper to download the document in pdf and docx format. I am using dynamic jasper report because the positions of jasper subreport may vary.

My jasper sub report have a title and a detail band.

enter image description here

output is

enter image description here

Now my problem is a border. A border is required like:

enter image description here

I tried to set rectangle, frame but all failed because two bands did not share one palate(component).

My requirement is a border via jasper report or via dynamic jasper. I have no idea how to set the border.

EDIT........................................................................

I also tried to set the border using a frame and rectangle via dynamic jasper code and the output is:

enter image description here

frame and rectangle not covering whole subreport. Here is my code:

JRDesignRectangle rectangle = new JRDesignRectangle();
//JRDesignFrame rectangle = new JRDesignFrame();
rectangle.setX(subReport.getX());
rectangle.setY(subReport.getY());
rectangle.setHeight(subReport.getHeight());
rectangle.setWidth(subReport.getWidth());
rectangle.setPositionType(PositionTypeEnum.FLOAT);
band.addElement(rectangle);
MKB
  • 7,587
  • 9
  • 45
  • 71

2 Answers2

3

If you are using jasper report plugin, you can open the JRXML file and say something like

 <box>
        <topPen lineWidth="1.0"/>
        <leftPen lineWidth="1.0"/>
        <bottomPen lineWidth="1.0"/>
        <rightPen lineWidth="1.0"/>
    </box>

Jasper reports come with an excellent designer called 'IReport Designer'. You can use concept of frames in IReport designer and put your sub-report inside the frame and then apply the border properties on the frame itself. You can also find BorderAroundTable useful. I would definitely recommend these links as well.

How to add border to a subreport

Frame Around Two Subreports

Border In Jasper Report

Let us know if this solution works for you.

If it can work for subreport having summary and page header, then it can help your case as well.

Editing and adding master report and subreport code having border

Master Report Source Code

<?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="testborder" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <background>
        <band splitType="Stretch"/>
    </background>
    <detail>
        <band height="421" splitType="Stretch">
            <subreport>
                <reportElement x="25" y="148" width="200" height="100"/>
                <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource()]]></dataSourceExpression>
                <subreportExpression><![CDATA["C:\\jaspersamples\\testborder_subreport1.jasper"]]></subreportExpression>
            </subreport>
            <frame>
                <reportElement x="45" y="119" width="390" height="176"/>
                <box>
<topPen lineWidth="2.0" lineStyle="Solid"/>
<leftPen lineWidth="2.0" lineStyle="Solid"/>

                    <bottomPen lineWidth="2.0" lineStyle="Solid"/>
                    <rightPen lineWidth="2.0" lineStyle="Solid"/>
                </box>
            </frame>
        </band>
    </detail>
</jasperReport>

Subreport source code

<?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="testborder_subreport1" language="groovy" pageWidth="802" pageHeight="555" orientation="Landscape" whenNoDataType="AllSectionsNoDetail" columnWidth="802" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0">
    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <background>
        <band splitType="Stretch"/>
    </background>
    <pageHeader>
        <band height="29" splitType="Stretch">
            <staticText>
                <reportElement x="317" y="5" width="100" height="20"/>
                <textElement/>
                <text><![CDATA[HELLO TEST]]></text>
            </staticText>
        </band>
    </pageHeader>
    <summary>
        <band height="29" splitType="Stretch">
            <staticText>
                <reportElement x="317" y="0" width="100" height="20"/>
                <textElement/>
                <text><![CDATA[i am testing BORDER]]></text>
            </staticText>
        </band>
    </summary>
</jasperReport>

The output is somewhat like this

enter image description here

Community
  • 1
  • 1
benz
  • 4,561
  • 7
  • 37
  • 68
  • Code you provide make a box around a component and link suggest border a subreport using a frame and a rectangle. But in my sureport i have title and detail band and frame and rectangle can not cover both because a component cannot cross band boundary. I edited my post, please have a look. – MKB Aug 12 '13 at 13:44
  • Hi, i tried a sample a subreport having summary band and title band and put it in the frame and it was able to draw the border around it. I am editing question to post the code for subreport and master report. – benz Aug 12 '13 at 17:19
  • I have tries your code and it perfectly fine. But when I replace your subreport with my subreport then only box is shown when I download even static contents are not displayed. – MKB Aug 13 '13 at 05:35
  • while the frame is being selected, right click to open the dialog menu bar and there is an option send to back, click that now all your subreports will be infront and frame backward. – benz Aug 13 '13 at 05:45
  • I did as you suggest but the result is same. I am sending dynamic data to the subreport, may be I am doing something wrong there. I just place my subreport in the main report you provide, is there any special way to pass the fields and parameters to subreport from a main report. – MKB Aug 13 '13 at 06:04
  • Hi, yes there is a specific way to pass the parameters using property maps. Its pretty convenient to use property maps. – benz Aug 13 '13 at 06:40
  • Can you please provide some link or steps how can I send data(data from database using fields and data via parameters) from main report and get/use in subreport. Thanks..,. – MKB Aug 13 '13 at 12:04
  • What approach are you using for it? Are you using embeded query as a datasource or using POJO's act a datasource to feed in the report? – benz Aug 13 '13 at 13:07
  • I am sending a model(POJO) from actions. – MKB Aug 13 '13 at 13:17
  • OK, I am able to pass the data to subreport the problem is that detail band is not shown. If I am placing my text field in summary band than data is shown but only once. I need details band because detail band can iterate on data. – MKB Aug 13 '13 at 14:00
  • check in your properties what is given in When no data property of Report properties. Is All section not detail selected? – benz Aug 13 '13 at 14:04
  • Yes, All section no data is selected. – MKB Aug 13 '13 at 14:08
0

You may enclose your subreport into a frame using IReport or Jaspersoft Studio. The steps of Jaspersoft Studio:

  1. Select main report and open Outline View
  2. Find subreport element and right click it.
  3. Select Enclose into Frame.
  4. Open Frame element's Properties.
  5. Go to Borders Tab and select the border choice that you want.