• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JasperReports 3.0.0 and Sub reports

 
RatiKanta pal
Ranch Hand
Posts: 88
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 88
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 88
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Something like the printWhenExpression element above should do the trick.
 
RatiKanta pal
Ranch Hand
Posts: 88
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 88
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic