Jump to content
Changes to the Jaspersoft community edition download ×

Passing parameters between subreports


sureshk

Recommended Posts

Hi,

Is there any workaround to pass parameters between subreports?. Subreports are in a main report detail section.I can do this if it is in Last page footer or summary, not working if it is placed in any other section.

Any help will be really crossing one more milestone in iReport design.

Regards
Suresh

Link to comment
Share on other sites

  • 3 weeks later...
  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

If both the subreports are placed on the same band, straightforwardly passing a value returned from one of the subreport to the second one would not work because the value is not yet returned at the time the parameter value expressions are evaluated.

 

There are (at least) two ways to work around this (I assume that the second subreport is placed under the first one):

Introduce a dummy group which breaks at each row and place the second subreport in the group's footer. This ensures that the parameter values for the second subreport are evaluated after the first subreport returned the value.

Don't use the standard mechanism for returning values from subreports, use a value holder subreport parameter instead. The first subreport would use a dummy expression to save the value in the holder and the second one would retrieve it from the holder.[/ol]

 

HTH,

Lucian

Link to comment
Share on other sites

I understand the first solution, but not the second one. Could you describe what you mean with a holder?

 

i cannot use the first solution (and maybe not even the second) because I have only one Subreport in the Detail Band, that gives a return value back.

I want to take a value from the subreport and give it to the (same) subreport in the "next" detail value.

I want to use this to start calculating values in the Subreport from a startpoint I know from the last Subreport. I want to use this for faster Report generation.

Link to comment
Share on other sites

If you want to pass the value returned from a subreport to the same subreport in the next detail row, the straightforward approach should work. Be careful to set calculation="System" and not to set resetType="None" for the variable in the master report. See the attached sample.

 

By a holder I meant an object which can store a value, something like

Code:

class Holder {
Object value;
void setValue(Object value);
Object getValue();
}

 

You could have a variable of this type in the master, pass it to the subreport as a parameter and, in the subreport (using a scriptlet or a dummy expression), store a value in the holder. The same holder would be passed to the second subreport which would retrieve the value from it.

 

HTH,

Lucian [file name=subrep.zip size=1261]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/subrep.zip[/file]

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...