sbyrne Posted April 17, 2015 Share Posted April 17, 2015 I am using datasourceExpression to call a static method that builds my custom data source. It there a way to access the subreportParameter map from my static method?Instead of this:<subreport> <dataSourceExpression><![CDATA[com.example.MyDataSourceUtil.createDataSource($F{myField},$P{myParam})]]></dataSourceExpression></subreport>[/code]I would like to do this:<subreport> <subreportParameter name="myField"> <subreportParameterExpression><![CDATA[$F{myField}]]></subreportParameterExpression> </subreportParameter> <subreportParameter name="myParam"> <subreportParameterExpression><![CDATA[$P{myParam}]]></subreportParameterExpression> </subreportParameter> <dataSourceExpression><![CDATA[com.example.MyDataSourceUtil.createDataSource()]]></dataSourceExpression></subreport> [/code]and access he parameter map somehow inside createDataSource(). Link to comment Share on other sites More sharing options...
Tom C Posted April 17, 2015 Share Posted April 17, 2015 "subreportParameter" is the linkage used in JasperReports engine to communicate between two report classes (main and sub report). What is the reason that prevents you from using your class method bearing the data signature such as createDataSource($F{myField},$P{myParam}) in your sub report call? Link to comment Share on other sites More sharing options...
sbyrne Posted April 17, 2015 Author Share Posted April 17, 2015 My static method does this:CustomReportDataSource ds = (CustomReportDataSource) RepositoryUtil .getThreadRepositoryContext().getRepository().getResource( null, dataSourceUri, null );Map properties = ds.getPropertyMap();MyDataSourceService service = new MyDataSourceService(); // implements ReportDataSourceService// cut - Read properties from the map and set them to service via it's settersMap params = new HashMap();// cut - Set params from args to static methodservice.setReportParameterValues( params );return params.get( JRParameter.REPORT_DATA_SOURCE );[/code]If I had a better way to get the subreport parameters, I could make this completely generic (for any ReportDataSourceService implementation, not just MyDataSourceService).I figured that Jasper server probably had a method that did just this - give it the URI to the data source, and it creates the ReportDataSourceService, sets the properties, and creates a JRDataSource via setReportParameterValues(Map), but I couldn't find it. So I figured I would write my own, but I cannot find access to the subreport parameters generically. Link to comment Share on other sites More sharing options...
Tom C Posted April 18, 2015 Share Posted April 18, 2015 I don't think there's a public JR API to intercept <subreportParameter> or <parametersMapExpression> elements in JasperFillManager class where report execution is invoked. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now