Home
Analytics
parameter passed from jsp to SQL query where clause in BIRT reports
neetira
Hi
a) I have a parameter in a jsp page in a Struts application.
b) I have a JDBC data source and Data set in BIRT reports.
c) the SQL query is "select Contents from user where Header = ? "
d) I have a ReportParameter called HeaderParameter.
e) I have a dataset Parameter also which is linked to the ReportParameter.
When I run the application, the parameter from the jsp page should be passed to the BIRT report as the value for ? in the where clause.
I have put the parameter in the application like request.getSession.setAttribute("a1", a1);
in the beforeOpen of the dataset, I have added the following:
var session = reportContext.getHttpServletRequest().getSession();
var myid = session.getAttribute("a[1]");
When I run the application, the parameter from the jsp page should automatically be inserted in the sql query and I want the values
to be displayed on the report.
I am not able to insert the value in the query. When I run the application, I get the Parameter page for the ReportParameter, which defeats
the idea of passing the parameter from jsp.
Can somebody help me?
Thanks
neeti
Find more posts tagged with
Comments
bhanley
You should not need the extra work on the scripting tier. You need to bind the report parameter to the Data Set parameter. To do this, open the Data set for editing and look at the "Property Binding" section. Once you bind the parameter to the Data Set, all you need to do is pass the parameter value into the report and everything will be handled for you.
How are you rendering the report? If you are targeting a URL, simply append the parameter name onto the URL, i.e. ¶meterName=parameterValue.
Good Luck!
pauljin
Hi you could make use of request object instead of session object.
make use of request.setAttribute() and pass the request object to birt. You could set it either in controller or in jsp it self
In birt get the parameter with reportContext.getHttpServletRequest().getAttribute(<attribute>) method and assign it to the dataset parameter.
It should work in this way
neetira
<blockquote class='ipsBlockquote' data-author="bhanley"><p>You should not need the extra work on the scripting tier. You need to bind the report parameter to the Data Set parameter. To do this, open the Data set for editing and look at the "Property Binding" section. Once you bind the parameter to the Data Set, all you need to do is pass the parameter value into the report and everything will be handled for you.<br />
<br />
How are you rendering the report? If you are targeting a URL, simply append the parameter name onto the URL, i.e. ¶meterName=parameterValue.<br />
<br />
Good Luck!</p></blockquote>
<br />
if I use the "Property Binding", then what do I use in the "Query" tab of the Dataset? <br />
<br />
I want the query to be "select Contents from Contents_user where Header in (?);" - the parameter is a list of values like 'A1','A2'. <br />
<br />
I have a dataset parameter called "param_1" and report parameter called "header parameter". Right now, I am trying to set the "header parameter" by reportContext.getHttpServletRequest().getSession().getAttribute("list"); <br />
<br />
What do i write in the "Query" tab and in "Property Binding" of the dataset?<br />
Also, I am trying to put "list" as a String = 'A1','A2', so that the "header parameter" = 'A1','A2' in order to have the query as "select Contents from Contents_user where Header in ('A1','A2');" <br />
<br />
When I run the application, it gives me error that <br />
"<br />
org.eclipse.birt.data.engine.odaconsumer.PreparedStatement doSetNull( int )<br />
SEVERE: Cannot set a null value to parameter 1.<br />
Cannot set preparedStatement null value.<br />
SQL error #1: com.microsoft.sqlserver.jdbc.SQLServerException: There is no metadata.<br />
<br />
org.eclipse.birt.report.data.oda.jdbc.JDBCException: Cannot set preparedStatement null value.<br />
SQL error #1: com.microsoft.sqlserver.jdbc.SQLServerException: There is no metadata.<br />
"<br />
<br />
Though the value of "list" is 'A1','A2', somehow the application is finding "null".<br />
<br />
I have tried with the value of "list" as A1,A2 also, but the same error comes.<br />
The table and the values for columns Contents and Header with the values A1, A2 are present.<br />
<br />
I cant understand how the null value is coming. <br />
<br />
thanks<br />
Neeti
neetira
<blockquote class='ipsBlockquote' data-author="pauljin"><p>Hi you could make use of request object instead of session object. <br />
make use of request.setAttribute() and pass the request object to birt. You could set it either in controller or in jsp it self<br />
<br />
<br />
In birt get the parameter with reportContext.getHttpServletRequest().getAttribute(<attribute>) method and assign it to the dataset parameter.<br />
<br />
<br />
It should work in this way</p></blockquote>
<br />
hey pauljin<br />
<br />
In JSP, i assigned the values I am passing to "list" using request.setAttribute("list", parameter);<br />
<br />
In BIRT, in initialize function of the report, i put the following,<br />
<br />
var session = reportContext.getHttpServletRequest().getSession();<br />
<br />
var myid = session.getAttribute("list");<br />
<br />
reportContext.setParameterValue("Header_Param", myid );<br />
<br />
here, "Header_Param" is the report parameter. <br />
<br />
In your post, you said that we can assign to the dataset parameter. <br />
<br />
What I did, is create a dataset parameter (param_1) and then put its default value as the report parameter(Header_Param) and then do the above.<br />
<br />
I thought if you have a dataset parameter, you have to have a report parameter and put the default value of the dataset parameter as the report parameter.<br />
<br />
I tried using the dataset parameter instead of the report parameter. but it didnt help me.
neetira
<blockquote class='ipsBlockquote' data-author="pauljin"><p>Hi you could make use of request object instead of session object. <br />
make use of request.setAttribute() and pass the request object to birt. You could set it either in controller or in jsp it self<br />
<br />
<br />
In birt get the parameter with reportContext.getHttpServletRequest().getAttribute(<attribute>) method and assign it to the dataset parameter.<br />
<br />
<br />
It should work in this way</p></blockquote>
<br />
hi pauljin<br />
<br />
how do i pass the request object to birt?<br />
<br />
i have a struts application which has report capabilities in MyEclipse. <br />
I have a jsp called table.jsp. In its action class, TableAction.java, i have put<br />
request.setAttribute("list", a1);<br />
<br />
table.jsp forwards to report.jsp which is the jsp page for the BIRT report. <br />
<br />
In the initialize of the BIRT report, i have put <br />
<br />
var request = reportContext.getHttpServletRequest()<br />
var myid = request.getAttribute("list"); <br />
reportContext.setParameterValue("Header_Param", myid );<br />
<br />
I think I am getting a null value for "Header_Param" as my query does not execute and it keeps giving an error that 'cannot set null value to parameter 1"<br />
<br />
can you tell me how to send request object to birt?<br />
<br />
neeti
bhanley
You are missing two things based on my understanding. Let me try and summarize.
1) You have a query that needs to accept a dynamic parameter. The place holder for the dynamic value in the query should be a question mark. It appears you have this correct.
2) You need a report parameter for the report to accept the value needed by the query. I think you have this set up correctly as well.
3) You then need to bind the report parameter to the data set's query. If you open up the data set for editing, you will see a "Parameters" group on the left side. When you click that, you will see a parameter already there. This parameter (param_1) is auto-created by BIRT when you add a place holder (?) to a query (I think you mentioned you have seen this entry already). If you look on the data set parameter settings for param_1, there is a drop-down that will allow you to select a report parameter to bind to. This will force the query to use the value supplied as the report parameter inside the query.
Having done all this, you should have closed the loop between the report parameter and the data set.
Good Luck!
neetira
<blockquote class='ipsBlockquote' data-author="bhanley"><p>You are missing two things based on my understanding. Let me try and summarize.<br />
<br />
1) You have a query that needs to accept a dynamic parameter. The place holder for the dynamic value in the query should be a question mark. It appears you have this correct.<br />
<br />
2) You need a report parameter for the report to accept the value needed by the query. I think you have this set up correctly as well.<br />
<br />
3) You then need to bind the report parameter to the data set's query. If you open up the data set for editing, you will see a "Parameters" group on the left side. When you click that, you will see a parameter already there. This parameter (param_1) is auto-created by BIRT when you add a place holder (?) to a query (I think you mentioned you have seen this entry already). If you look on the data set parameter settings for param_1, there is a drop-down that will allow you to select a report parameter to bind to. This will force the query to use the value supplied as the report parameter inside the query.<br />
<br />
Having done all this, you should have closed the loop between the report parameter and the data set. <br />
<br />
Good Luck!</p></blockquote>
<br />
<br />
Hi Bhanley<br />
<br />
I did all the 3 steps which you mentioned. <br />
<br />
But when i run the application, it is not taking the parameter which I pass. <br />
<br />
I tried the Property binding tab where I wrote the entire query as<br />
<br />
this.queryText = "select * from Contents_user where Header in(' " +params["Header_Param"].value+ " ')" ;<br />
<br />
and in Query tab of the data set, i have the query as <br />
select * from Contents_user<br />
<br />
and in initialize function of the report, i put <br />
<br />
var session = reportContext.getHttpServletRequest().getSession();<br />
var myid = session.getAttribute("list");<br />
reportContext.setParameterValue("Header_Param", myid);<br />
<br />
now when i run the program, it is working.<br />
<br />
the only difference i had in both ways, - <br />
for one, i had a dynamic parameter in the query itself and made a dataset parameter and bound to the report parameter<br />
<br />
for 2nd, i had the entire query written in Property binding of the data set<br />
<br />
but somehow only the 2nd method is working now. 1st method is not taking the value. <br />
<br />
Is it because of the IN clause? if we have an IN clause in the query, is it possible to use only the Property binding method? Why is it not possible to use the Dataset parameter bound to report parameter method?
raghul
I tried the Property binding tab where I wrote the entire query as
this.queryText = "select * from Contents_user where Header in(' " +params["Header_Param"].value+ " ')" ;
and in Query tab of the data set, i have the query as
select * from Contents_user
and in initialize function of the report, i put
var session = reportContext.getHttpServletRequest().getSession();
var myid = session.getAttribute("list");
reportContext.setParameterValue("Header_Param", myid);
the only difference i had in both ways, -
for one, i had a dynamic parameter in the query itself and made a dataset parameter and bound to the report parameter
for 2nd, i had the entire query written in Property binding of the data set
but somehow only the 2nd method is working now. 1st method is not taking the value.
Is it because of the IN clause? if we have an IN clause in the query, is it possible to use only the Property binding method? Why is it not possible to use the Dataset parameter bound to report parameter method?
[/quote]
Can you please elaborate the 1st and the 2nd method?
I have right now created only the report but not any project linking with JSP.
I thought I would try generating report first and then link it with JSP.
Please Help