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

Problem in passing parameter


abdujaparov

Recommended Posts

Hi,

I have a report composed by some subreports. I need to pass a parameter to one of these subreports.

The parameter I want pass to is:

BigDecimal diffMin = new BigDecimal(23000);

My Java code is:

 

List internalDeals=processManager.getInternalDeals(result);
            List externalDeals=processManager.getExternalDeals(result);
            List resultList= new ArrayList();
            resultList.add(result);
            Report mainReport = new Report(ReportManager.class.getClassLoader().getResourceAsStream(
                    ReportConstant.oneToManyReportPath_7));
            mainReport.compile();
            mainReport.setDatasource(new JRHibernateDataSource(resultList));
            Report configuration = getConfigurationReport(result.getProcess(),ReportConstant.oneToManyConfigurationPath);
            configuration.getParameters().put("diffMinValuta", diffMin);
            mainReport.getParameters().put("configuration", configuration);
            List rebuildedElementSensitivity=FactoryBean.buildReportTimeGridDTO_7(elements, result.getRatioSensitivity().getSensitivityValues());
            mainReport.getParameters().put("labelsConfiguration", getLabelsConfigurationReport(rebuildedElementSensitivity,ReportConstant.oneToManyLabelsPath));
            
            mainReport.getParameters().put("riskSensitivity", result.getRiskSensitivity().getSensitivityValues());
            mainReport.getParameters().put("hedgeSensitivity",result.getHedgeSensitivity().getSensitivityValues());

 

The main report is many_to_many7.jxrml, the parameter must be contained in one subreport of many_to_many7.jxrml. The subreport is configuration.jrxml (in the java code thi report is returned from the method getConfigurationReport.

I passed the parameter to this last report in this way:

configuration.getParameters().put("diffMinValuta", diffMin);

In configuration.jrxml I inserted these lines of code:

....
<parameter name="diffMinValuta" isForPrompting="false" class="java.math.BigDecimal"/>
.......
......
......
<textFieldExpression class="java.math.BigDecimal"><![CDATA[$P{diffMinValuta}]]></textFieldExpression>
.....
.....
.....

 

When I create a report instead of the value of diffMinValuta I see null.

The value I pass in the java code is different from null.

What do I forget?

Could someone help me?

How can I solve?

Thanks, bye bye.

Link to comment
Share on other sites

  • Replies 19
  • Created
  • Last Reply

Top Posters In This Topic

Hi

I dont know the code which was written by you.

From my understanding you want to passs parameter from master report to subreport.

But i can tell you in ireport how one can pass the parameter from master report to subreport.

step1: create one master report with all the parameters which will require in subreport.(if Parameter name in both the reports same it will be good  )

step2:drag the subreport icon from the toolbox it will ask for the connection .Give same connection as the master report has.

step3:map the parameters with sub report.(If you didnt create parameters for main report then in the wizzard it will not appear.so plz follow steps)

step4: when u run the master report it will prompt the parameter and that parameter value is passed to the subreport.

 

Thanks

Prasad

Link to comment
Share on other sites

Hi,

the problem is not with the map. Because I pass the value to the map of the subreport.

But in this way the value is not filled in the subreport.

Instead if I pass the parameter to the map of the main report and than I fill the report I see the value.

If I fill the subreport (with JaspeFillManager.fillReport I receive a JasperPrint that I can not use).

So my problem is:

How can I fill a subreport and then insert the subreport in the mainreport? Or how can I pass a parameter from the main report to the subreport?

Thanks, bye bye.

Link to comment
Share on other sites

hi,

For passing values from master report to sub report u can use subreort parameters

masterreport :-

<subreportParameter name="time">

<subreportParameterExpression><![CDATA[$F{CLOSURE_TIME}></subreportParameterExpression></subreportParameter>

subreport:- <parameter name="time" isForPrompting="false" class="java.lang.String"/>

Regrds,

Dayana



Post Edited by dayana at 07/10/2009 08:54
Link to comment
Share on other sites

Hi,

in the master report I have:

 

.....
<parameter name="diffMinValuta" isForPrompting="false" class="java.math.BigDecimal"/>
......
<subreport  isUsingCache="true">
                    <reportElement
                        x="-1"
                        y="-1"
                        width="320"
                        height="0"
                        key="configuration"
                        positionType="Float"/>
                    <subreportParameter  name="type">
                        <subreportParameterExpression><![CDATA["internal"]]></subreportParameterExpression>
                    </subreportParameter>
                    <subreportParameter  name="totalSensitivity">
                        <subreportParameterExpression><![CDATA[$P{riskSensitivity}]]></subreportParameterExpression>
                    </subreportParameter>
                    <subreportParameter  name="diffMinValuta">
                        <subreportParameterExpression><![CDATA[$P{diffMinValuta}]]></subreportParameterExpression>
                    </subreportParameter>                                                        
                    <dataSourceExpression><![CDATA[((com.intesasanpaolo.tps.manager.report.Report)$P{internalDealReport}).getDatasource()]]></dataSourceExpression>
                    <subreportExpression  class="net.sf.jasperreports.engine.JasperReport"><![CDATA[((com.intesasanpaolo.tps.manager.report.Report)$P{internalDealReport}).getReport()]]></subreportExpression>
                </subreport>
.......

In the subreport I have:

....
<parameter name="diffMinValuta" isForPrompting="false" class="java.math.BigDecimal"/>
......
<textFieldExpression class="java.math.BigDecimal"><![CDATA[$P{diffMinValuta}]]></textFieldExpression>
.......
....

 

But I always see null.

In the java code I put the parameter in the map of the main report. I do not put it on the map of the subreport.

What can I do?

Thanks, bye bye

Link to comment
Share on other sites

Hi,

The datasource of the master report and the datasource of the subreport are different.

So what can I wrong?

The main report datasource is:

EResult result = processManager.getSingleResult(resultId);

List resultList= new ArrayList();
            resultList.add(result);

masterReport.setDatasource(new JRHibernateDataSource(resultList));

 

 

The subreport datasource is:

List econfigList = new ArrayList();

EConfiguration econfig = process.getConfiguration();
            elements = econfig.getTimeGridPrototype().getElements();
            econfigList.add(econfig);

subReport.setDatasource(new JRHibernateDataSource(econfigList));

 

What can I do?

Thanks, bye bye.

Link to comment
Share on other sites

Hi,

 

You seem to use some classes of your own, like Report. So we are not sure how the parameters actually get into the fill process of JasperReports.

Have you tried to display the value of the paramter in the master, using a text field, just for debugging purposes?

If the parameter is displayed correctly in the master, then the problem must be somewhere between the master and the subreport. In which case we sould need to see the JRXML files involved.

 

I hope this helps.

Teodor

 

Link to comment
Share on other sites

Hi

In the master report the parameter I pass is printed correctly.

My own Report class is:

ublic class Report {

    public static final int REPORT_FLUSSO_LAVORAZIONE = 1;
    // parametri del report
    private Map parameters;
    // report
    private JasperReport report;
    // datasource del report
    private JRHibernateDataSource datasource;
    // contenitore del file jrxml del report
    private JasperDesign reportDesign;

    Report() {}

    public Report(String JRPath) throws ReportException {
        try {
            this.reportDesign = JRXmlLoader.load(JRPath);
        } catch (JRException e) {
            throw new ReportException("Errore nei parametri del report - " + e.getMessage(),
                    ReportException.REPORT_COSTRUCTORS_EXCEPTION, e);
        }
    }

    public Report(File JRFile) throws ReportException {
        try {
            this.reportDesign = JRXmlLoader.load(JRFile);
        } catch (JRException e) {
            throw new ReportException("Errore nei parametri del report - " + e.getMessage(),
                    ReportException.REPORT_COSTRUCTORS_EXCEPTION, e);
        }
    }

    public Report(InputStream JRInputStream) throws ReportException {
        try {
            this.reportDesign = JRXmlLoader.load(JRInputStream);
        } catch (JRException e) {
            throw new ReportException("Errore nei parametri del report - " + e.getMessage(),
                    ReportException.REPORT_COSTRUCTORS_EXCEPTION, e);
        }
    }

    public Report(String JRPath, JRHibernateDataSource datasource) throws ReportException {
        try {
            this.reportDesign = JRXmlLoader.load(JRPath);
            this.datasource = datasource;
        } catch (JRException e) {
            throw new ReportException("Errore nei parametri del report - " + e.getMessage(),
                    ReportException.REPORT_COSTRUCTORS_EXCEPTION, e);
        }
    }

    public Report(File JRFile, JRHibernateDataSource datasource) throws ReportException {
        try {
            this.reportDesign = JRXmlLoader.load(JRFile);
            this.datasource = datasource;
        } catch (JRException e) {
            throw new ReportException("Errore nei parametri del report - " + e.getMessage(),
                    ReportException.REPORT_COSTRUCTORS_EXCEPTION, e);
        }
    }

    public Report(InputStream JRInputStream, JRHibernateDataSource datasource) throws ReportException {
        try {
            this.reportDesign = JRXmlLoader.load(JRInputStream);
            this.datasource = datasource;
        } catch (JRException e) {
            throw new ReportException("Errore nei parametri del report - " + e.getMessage(),
                    ReportException.REPORT_COSTRUCTORS_EXCEPTION, e);
        }
    }

    public void reportLoader(String JRPath) throws ReportException {
        try {
            this.reportDesign = JRXmlLoader.load(JRPath);
        } catch (JRException e) {
            throw new ReportException("Errore nel caricamento del report - " + e.getMessage(),
                    ReportException.REPORT_LOAD_EXCEPTION, e);
        }
    }

    public void reportLoader(File JRFile) throws ReportException {
        try {
            this.reportDesign = JRXmlLoader.load(JRFile);
        } catch (JRException e) {
            throw new ReportException("Errore nel caricamento del report - " + e.getMessage(),
                    ReportException.REPORT_LOAD_EXCEPTION, e);
        }
    }

    public void reportLoader(InputStream JRInputStream) throws ReportException {
        try {
            this.reportDesign = JRXmlLoader.load(JRInputStream);
        } catch (JRException e) {
            throw new ReportException("Errore nel caricamento del report - " + e.getMessage(),
                    ReportException.REPORT_LOAD_EXCEPTION, e);
        }
    }

    public JasperReport compile() throws ReportException {
        try {
            this.report = JasperCompileManager.compileReport(this.reportDesign);
        } catch (JRException e) {
            throw new ReportException("Errore nella compilazione del report - " + e.getMessage(),
                    ReportException.REPORT_COMPILE_EXCEPTION, e);
        }
        return this.report;
    }

    public Map getParameters() {
        if (this.parameters == null) this.parameters = new HashMap();
        return parameters;
    }

    public void setParameters(Map parameters) {
        this.parameters = parameters;
    }

    public JasperReport getReport() {
        return report;
    }

    public void setReport(JasperReport report) {
        this.report = report;
    }

    public JRHibernateDataSource getDatasource() {
        return datasource;
    }

    public void setDatasource(JRHibernateDataSource datasource) {
        this.datasource = datasource;
    }
}

The parameter arrives correctly to the master report then there is a problem in the passage from the master to the subreport.

What can I do?

Thanks, bye bye

 

Link to comment
Share on other sites

Hi,

 

Just as a side note, I see you are compiling reports at runtime. Are you sure you need to do this? If your JRXML files do not change at runtime, you don't have to compile them. You should compile them only once, when you build your application source code. Here's an FAQ about this:

http://jasperforge.org/uploads/publish/jasperreportswebsite/trunk/faq.html?group_id=252#FAQ22

 

Now, getting back you your original problem. Are you sure the subreport datasource has at least one record? Maybe the subreport does not display anything at all, because it does not have any data in the data source. You could change this behavior by setting whenNoDataType="AllSectionsNoDetail" for your subreport template. This is just a guess, because you have not sent the JRXML files involved.

 

I hope this helps.

Teodor

 

Link to comment
Share on other sites

Mmmm,

Another way to go over the problem.

The datasource I pass to the subreport contains only one object of this class EConfiguration.

So this class contains a set of another object, ECurrenciesDiffMin.

The last object contain the fields a string and a number.

The parameter I am not able to pass the subreport is the number of one of the object ECurrenciesDiffMin I have in the set contained in the EConfiguration (the datasource).

So does It exist a method to check the set to get the correct object ECurrenciesDiffMin from the set contained in EConfiguration?

Because if I can check the set and get the correct object ECurrenciesDiffMin I do not need the parameter.

Thanks bye bye.

Link to comment
Share on other sites

Hi,

Yes I know, but Can I create a loop for? Can I insert an if statemente?

These are the problems. I am able to get the set, but I don't know If I can create a loop on the set and then use an if statemente on each element of the set (taken with the loop).

Thanks, bye bye.

Link to comment
Share on other sites

So you basically want to execute some code, not only Java expressions. In that case, I suggest to isolate all that code in a separate utility class that has public static methods and you call them from the report expressions. You just need to make sure the utility class is available in the classpath at runtime.

 

I hope this helps.
Teodor

 

Link to comment
Share on other sites

Hi,

 

I'm not saying you have to give up passing parameters. You still need to, but then you have to write a class in oders to iterate through that collection parameter you are passing, as iterations cannot be made in the expression itself.

 

I hope this is clear enough, otherwise there is little I could add to it.

 

Thanks,
Teodor

 

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