• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JasperReports 3.0.0 and Sub reports

 
Ranch Hand
Posts: 88
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic