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

File as parameter


carolopia

Recommended Posts

  • Replies 7
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Use a text file as a datasource or read parameters/properties from a text file?  Will assume read parameters/properties froma text file.  I can think of 3 potential ways of doing this but hard to say which is best for you as I'm not sure exactly what you are trying to accomplish.

Most likely choice would be to use built in functionality of Resource Bundles, typically used for doing string localization but it's essentially a file containing key/value pairs and the integration into iReport is already there so you can use it to store property values.

Do a google search or search the forum for Resource Bundles and you should find everything you need. They are very powerful.

Couple other options:

1) Create a custom scriptlet which will read the file and pull out the values you are looking for.

2) Depending on how you have integrated Jasper Reports into your application (if you have at all) then you could modify your implementation to automatically read files and set parameters within the report automatically. I do this for my implementation where I have an XML definition for each report which allows me to set parameters (and other neat stuff :) ) outside of the report through a key/value combination and these are automatically passed to the report. Probably a little more involved but is an option.
 



Post Edited by jpauze at 04/28/2011 13:03
Link to comment
Share on other sites

Thanks jpauze for your help.

I need the data of the file to pass a SQL query, the query is like "select b, d, f from a where c in ("here put the data of the file") "
I use Jasperserver to integrate this report and I need pass the file as a parameter.
I don't know if is posible do this.

Regards,

Caro.

Link to comment
Share on other sites

Yes assumed that was what you were trying to do.   See if this helps.

Step 1

Let's say your report name is 'report1',  create a file in the same directory called 'report1.properties' then edit the file and add the following entry

IN_STATEMENT=(123455,123445, 512555, 125255)

If these are string columns then adjust to the following

IN_STATEMENT=('123455','123445', '512555', '125255' )

Step 2

Update your report and set the property Resource Bundle and set the value to 'Report1',  without quotes and don't put the .properties extension as it will automatically be looking for .properties file.

Step 3

Accessing the property is done via $R{} function so to get the value of the property in the resource bundle specify $R{IN_STATEMENT}  and this can be used in expressions.

Step 4

I don't think you can use $R{} as part of the SQL statement like you can with $P{} and $P!{} so you need to create a new Parameter on your report, call it IN_STATEMENT,  String (turn off prompt for value) and set the initial expression to $R{IN_STATEMENT}

Step 5

Adjust the SQL Statement to use the parameter,  for instance

SELECT field1, field2 FROM table1 WHERE field1 IN $P!{IN_STATEMENT}

Voila...

Hope it helps.

 

Link to comment
Share on other sites

It works perfect, thanks!!!!
Now I need other issue,  I need put this report in the JasperServer, I do this perfectly but what about the file? How can a user edit this one with the data to the query? Can they edit this file?
thanks!
Regards.
Caro.

Link to comment
Share on other sites

ah.... I am not a JasperServer user as we have embedded the JasperReports engine directly into our application due to license restrictions. You may want to check the JasperServer forum as I am 99.99% positive it supports user supplied parameters which can automatically populate parameters in your report on execution. May not need the above resource bundle option if you defined your parameters in JasperServer and have it supply your report with what's required.

 

On a side note, if you aren't using JasperServer and have integrated into your application with JavaReports then the only option you are going to have is to build the functionality yourself. I.e. from your application, prompt the user for parameters and then pass them into the report prior to execution.

 

Option 2 in my original response is how we do it, I have a config file which lists the avaialable parameters and whether they can be overriden by the user, defaults, data types etc.. and then out application allows the user to update the parameters before running the report. Works beautiful but this is just building functionality that JasperServer already has natively if you have the choice of using it.

Link to comment
Share on other sites

Thanks for your help. I owe you one.
I will search information in the Jasperserver forum. I hope find something that can it help me because is hard to change JasperServer to other application that I have many reports in JasperServer in production.
Again thanks for your help, Regards from Colombia.

Caro.

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