Jump to content
We've recently updated our Privacy Statement, available here ×

Fill report params with static value?


kschmitte

Recommended Posts

Hello all,

 

I'm facing the following issue:

There are quite a few reports with included subreports which I need to develop (in iReport). When I then import them into JasperServer, I need to change the parameter holding the path to the subreport.

As I don't want to keep differnet versions of the report, and also don't want to type in the report name each time I execute it, I decided to create a subreport connection as follows:

$P{SUBREPORT_DIR} + "reportName." + $P{Extension}.

This allows me to define the parameters before the execution.

 

Now my question (which is general and not only restricted to my use case above):

How can I define a static value which will be passed to my report as parameter (value)?

 

So, as an example: The above mentioned Parameter should get the value "repo:". How can I assign this value to the report parameter in JasperServer?

Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

OK, I might have been not exact enough ;)

What I tried so far:

1) Create a Datatype & an Input Control - this always uses the Parameters default value when I run the report.

2) Create a List of Vlaues (with only one value) + an Input Control - the same result as above.

 

What I'm looking for,

- is a kind of constant to set my parameter while running the report from JasperServer (best: connected to the report execution, not to the resource jrxml)

OR

- the same as above, only while running from within IReport

OR

- is a possibility to have different standard values for parameters dependant on the running place.

 

Thanks for your help!

 

Kai

Link to comment
Share on other sites

There is no such feature built in JasperServer (and I don't know about iReport), but you can achieve it relatively easily if you extend the JasperServed code.

 

You would need to extend com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.EngineServiceImpl (which is responsible for report executions) and change the "engineService" in applicationContext.xml to use your extended service class:

Code:

//the extended service class
package me;

public class MyEngineServiceImpl extends EngineServiceImpl {
protected Map getReportParameters(ExecutionContext context, Map requestParameters) {
Map reportParams = super.getReportParameters(context, requestParameters);

reportParams.put("SUBREPORT_DIR", "repo:"«»);
}
}

<!-- use the extended service class in applicationContext.xml -->
<bean id="engineService" class="me.MyEngineServiceImpl " destroy-method="release">
...

 

You could also implement a solution to have default parameter values per environment once you come up with a mechanism to distinguish the environments. You could have an explicit mechanism (e.g. create a JR property and manually set different values in the two environments), or employ some heuristics to automatically guess the environment (e.g. you could search for some specific classes). For instance:

Code:
[code]
//helper class
package me;

public class SubreportParameterHelper {
private final static String SUBREPORT_DIR;
static {
boolean isJasperServer;
try {
// if we find the JS repository class, we must be in JS
Class.forName("com.jaspersoft.jasperserver.api.metadata.common.service"«»);
isJasperServer = true;
} catch (ClassNotFoundException e) {
// otherwise we must be in iReport
isJasperServer = false;
}
SUBREPORT_DIR = isJasperServer ? "repo:" : "..value for iReport..";
}

public static String getSubreportDir() {
return SUBREPORT_DIR;
}
}

<!-- use the helper class in reports -->
<parameter name="SUBREPORT_DIR">
<defaultValueExpression>me.SubreportParameterHelper.getSubreportDir()</defaultValueExpression>
</parameter>

 

Regards,

Lucian

Post edited by: lucianc, at: 2007/07/26 13:15

Link to comment
Share on other sites

Hello lucianc,

 

thank you very much for this detailed answers!

I will try this within the next week and inform about the outcome.

 

Additionally I have created an Enhancement Request for this one: Artifact artf2385 : Add a constant value to fill Report Parameters

 

Kai

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...