carsten07 Posted February 22, 2007 Share Posted February 22, 2007 Hi, i'm evaluating ireport and i have a problem with my own Datasourceprovider. How can i access a report parameter in the datasourceprovider? Here is the code:Code:public class MyDatasourceProvider extends JRAbstractBeanDataSourceProvider{ private static Logger log = Logger.getLogger(MyDatasourceProvider.class); public MyDatasourceProvider() { super(Test.class); } /* * @see net.sf.jasperreports.engine.JRDataSourceProvider#create(net.sf.jasperreports.engine.JasperReport) */ public JRDataSource create(JasperReport report) throws JRException { Collection collection = null; JRParameter[] param = report.getParameters(); log.debug("Param: " + param.length); for(int i=0;i<param.length;i++) { log.debug("Param[" + i + "]: " + param.getName()); log.debug("Paramclass[" + i + "]: " + param.getClass()); log.debug("Paramvclass[" + i + "]: " + param.getValueClass()); log.debug("Param[" + i + "]: " + param.getDescription()); log.debug("Param[" + i + "]: " + param.getDefaultValueExpression()); } return new JRBeanCollectionDataSource(collection); } /* * @see net.sf.jasperreports.engine.JRDataSourceProvider#dispose(net.sf.jasperreports.engine.JRDataSource) */ public void dispose(JRDataSource arg0) throws JRException { } I see the params but i've no idea how to access them? Thanks in advance Carsten Link to comment Share on other sites More sharing options...
carsten07 Posted February 26, 2007 Author Share Posted February 26, 2007 Has nobody an idea? Link to comment Share on other sites More sharing options...
martynhiemstra Posted March 1, 2007 Share Posted March 1, 2007 This should be a plain and simple Java solution Add Code:private JRParameter[] params = null;to the class. In your create method dont say Code:[code]JRParameter[] param = report.getParameters();but sayCode:[code]this.params = report.getParameters(); Then create a getParams() method that returns the param array or create a method getParam(String name) that returns a param with a certain name. Or would you like to find out how to access the parameters from your report? Post edited by: martynhiemstra, at: 2007/03/01 07:19Post edited by: martynhiemstra, at: 2007/03/01 07:41 Link to comment Share on other sites More sharing options...
carsten07 Posted March 1, 2007 Author Share Posted March 1, 2007 Thank you for your post,but my problem is not to get a parameter.I've no idea how to access the value from a parameter. Carsten Link to comment Share on other sites More sharing options...
lukemcar Posted March 10, 2007 Share Posted March 10, 2007 I am trying to do the same thing. I have tryed many things but none have worked. Here is my latest attempt Code:public class MyDataSourceProvider extends JRAbstractBeanDataSourceProvider{// some code public JRDataSource create(JasperReport report) throws JRException { Object clubName = getParameterValue(report, "clubName"«»); // some code JRBeanArrayDataSource beanDataSource = new JRBeanArrayDataSource(this.items.toArray()); return beanDataSource; } public static Object getParameterValue(JasperReport report, String paramName) { JRParameter[] param = report.getParameters(); if(param != null) { for(int i = 0; i < param.length; ++i) { if(paramName.equals(param.getName())) { if(param instanceof JRValueParameter) { return ((JRValueParameter)param).getValue(); } } } return "no value"; } else { return "getParameters is Null"; } }} This last attempt seemed to be the most promising, but it seams that none of the parameters are of type JRValueParameter. If I find a solution I’ll post it. Link to comment Share on other sites More sharing options...
jinal Posted May 10, 2011 Share Posted May 10, 2011 I am facing the same problem. Has anybody got the solution for this? Thanks. Jinal 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