aspose file tools*
The moose likes Other Open Source Projects and the fly likes JasperReports 3.0.0 and Sub reports Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "JasperReports 3.0.0 and Sub reports" Watch "JasperReports 3.0.0 and Sub reports" New topic
Author

JasperReports 3.0.0 and Sub reports

RatiKanta pal
Ranch Hand

Joined: Nov 13, 2011
Posts: 68

Hi all,

Please read the problem statement stated below

>I have one master jrxml file which contains one query and also Have four sub reports.
>Depending on the result of the master query my sub report will execute suppose master query give me "1" first sub report will execute , if "2" second will execute and so on.
>Each of my sub report contains one one query each.

How to achive this??

Thanks in advance.
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1030
    
    5

I don't have access to a machine at the moment but something like the following should satisfy your requirement:

- Assign the value of your main query to a field which should be set to be generated at runtime.
- Apply a printExpression to the band containing each of your subreports, based upon the value of the field created.
E.g. mainQueryResult.equals("1") for subreport 1 and so on.

I'd be interested to know how you get on.
RatiKanta pal
Ranch Hand

Joined: Nov 13, 2011
Posts: 68

Hi James,

Thanks for your response .. Now could you please tell me how the syntax will be eg.suppose my sub report is sub1.jasper in master jrxml file how to place in between the condition.
like

if(mainQueryResult.equals("1"))
{
<subreport>
<reportElement positionType="Float" x="335" y="25" width="175" height="20" isRemoveLineWhenBlank="true" backcolor="#99ccff"/>
<subreportParameter name="City">
<subreportParameterExpression><![ CDATA[$F{City}]] ></subreportParameterExpression>
</subreportParameter>
<subreportExpression class="java.lang.String"><![CDATA["sub1.jasper"]] ></subreportExpression>
</subreport>
}
else if(mainQueryResult.equals("2"))
{
....
...
}



RatiKanta pal
Ranch Hand

Joined: Nov 13, 2011
Posts: 68

RatiKanta pal wrote:Hi James,

Thanks for your response .. Now could you please tell me how the syntax will be eg.suppose my sub report is sub1.jasper in master jrxml file how to place in between the condition.
like

if(mainQueryResult.equals("1"))
{
<subreport>
<reportElement positionType="Float" x="335" y="25" width="175" height="20" isRemoveLineWhenBlank="true" backcolor="#99ccff"/>
<subreportParameter name="City">
<subreportParameterExpression><![ CDATA[$F{City}]] ></subreportParameterExpression>
</subreportParameter>
<subreportExpression class="java.lang.String"><![CDATA["sub1.jasper"]] ></subreportExpression>
</subreport>
}
else if(mainQueryResult.equals("2"))
{
....
...
}



James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1030
    
    5



Something like the printWhenExpression element above should do the trick.
RatiKanta pal
Ranch Hand

Joined: Nov 13, 2011
Posts: 68

hi james,

But "<printexpressionwhen>" i think this will just check the value and if condition matched thn will print the data

but here i want,when my condition matched it will execute the the sub report block.

like

if(condition)
{

my sub report
}



how to do that?
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1030
    
    5

I'm not 100% sure but I think the subreport is not run if the printWhenExpression condition equates to false. You should be able to verify this with a suitable breakpoint in your code.
RatiKanta pal
Ranch Hand

Joined: Nov 13, 2011
Posts: 68

RatiKanta pal wrote:,

<printexpressionwhen> i think this will just check the value and if condition matched thn will print the data

but here i want,when my condition matched it will execute the the sub report block.

like

if(condition)
{

my sub report
}



how to do that?
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1030
    
    5

Did you see my last post? I still think printWhenExpression is what you need. If the condition is met, the subreport is generated; if the condition isn't met, no subreport is generated. Now, instead of simply repeating yourself, you could actually try this out and come back with the outcome.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JasperReports 3.0.0 and Sub reports