1

I need to pass parameters (variables) in to my report template when running a report. How do I do this? I am using the Java version of Windward.

David Thielen
  • 28,723
  • 34
  • 119
  • 193
  • Why are you asking a question that you immediately answer yourself? – maba Aug 26 '12 at 21:00
  • 1
    @maba Please take a look at the form when you click Ask Question. It is an option to ask and answer a question. For this case, we're going to post the most common questions (and answers) we get about programming with Windward so people can get immediate answers here. – David Thielen Aug 26 '12 at 21:03
  • OK. I suspected something like that. I didn't mean to sound rude or anything. – maba Aug 26 '12 at 21:07
  • @maba - not a problem. It definitely looks weird the first time you see it. – David Thielen Aug 26 '12 at 21:08

1 Answers1

1

You pass the parameters in by attaching them to each datasource. You can set a different set of parameters and values for each datasource.

You do this by creating a java.util.Map that contains the parameters. The key is a String with the variable name. The value can be a String, Number, or Date. The value type should match database column types if the variable will be used as a parameter in a select.

These are set in the datasource by calling DataSourceProvider.setMap(). Dom4jDataSource and JdbcDataSource both implement DataSourceProvider.

DataSourceProvider datasource = new JdbcDataSource("com.microsoft.sqlserver.jdbc.SQLServerDriver", "jdbc:sqlserver://localhost:1433;DatabaseName=Northwind", "username, "password");
Map map = new HashMap();
map.put("now", new Date());
datasource.setMap(map);

Note that variables are carried across datasources if multiple datasources are applied to a template. If a variable is set in the first datasource, and is not set in the second, it will retain its value from the first. If it is set in the second, that will override the saved value.

David Thielen
  • 28,723
  • 34
  • 119
  • 193