laloca Posted July 31, 2007 Share Posted July 31, 2007 Hi, Is there a possiblity to calculate a default value for a date parameter? I'm using JasperServer 2.0 and iReports 2.0 with an Oracle database. In SQL I would use SELECT last_day(add_months(SYSDATE,-2)) + 1 FROM dual to calculate the first day of the last month. I could code it in the SQL statememt but our users need to define their own date lines sometimes. Nevertheless the default use is to filter the data by last month and the first and last day of last month should be proposed in the according parameter fields. Any ideas? Thank you very much in advance :-) Susanne Link to comment Share on other sites More sharing options...
codyjasperForge Posted July 31, 2007 Share Posted July 31, 2007 You could create two parameters, one to hold the value of the input data, the other to do the calculation on that parameter. $P{inputData} expression = the users input $P{dateCalculated} expresssion = ${inputData}.doDateCalc() OR $P{dateCalculated} expression = java.util.Date().setTime().getHours().getDate().setDate() ... You could do the calculation using a scriptlet, or just embed you code in the parameters expression. All of which you would need to use Java API's to do so. e.g.(Date class, Calendar class, DateFormat class, etc) Does this help? Link to comment Share on other sites More sharing options...
laloca Posted July 31, 2007 Author Share Posted July 31, 2007 Thank you for your quick response. Unfortunately it's not the solution I'm looking (or hoping) for. I wish Jasper or the Jasperserver could calculate the default date lines by themselves depending on the actual date. The parameters should propose the date lines of last month eg. 1/6/2007 ($P{date_from}) and 30/6/2007 ($P{date_to}). It's quite boring to open the calendar, scroll back to last month, set the 1st day of this month, switch to the date_to parameter and do the same for the last day of last month. The parameters should be filled automatically when the user calls the report - so he only needs to start the report generation. In some rare cases the user wants to change these parameters, but in 99 % they want to filter to last month. Kind regards,Susanne Link to comment Share on other sites More sharing options...
lucianc Posted July 31, 2007 Share Posted July 31, 2007 laloca wrote:I wish Jasper or the Jasperserver could calculate the default date lines by themselves depending on the actual date. The parameters should propose the date lines of last month eg. 1/6/2007 ($P{date_from}) and 30/6/2007 ($P{date_to}). What is Jasper? JasperServer 2.0 evaluates parameter default value expressions and uses the result as initial value for the report input controls. This still means, of course, that you will need to write expressions to produce the parameter default values you want. Regards,Lucian Link to comment Share on other sites More sharing options...
codyjasperForge Posted July 31, 2007 Share Posted July 31, 2007 Isn't that the same as I suggested?$P{dateCalculated} should contain the default values of the newly calculated date, right? :huh: Link to comment Share on other sites More sharing options...
lucianc Posted July 31, 2007 Share Posted July 31, 2007 codyjasperForge wrote:Isn't that the same as I suggested?$P{dateCalculated} should contain the default values of the newly calculated date, right?:huh: Yes, it is. What I wanted to say is that JS 2.0 honors the default parameter values. Regards,Lucian Link to comment Share on other sites More sharing options...
laloca Posted August 2, 2007 Author Share Posted August 2, 2007 Hi, Thank you all for your useful tips. After some investigations and learnings in calculating dates in Java (im not really what you would call an experienced Java developer) I realized that I can't summarize the following as a default expression: Code:Calendar now = Calendar.getInstance(); now.add(Calendar.MONTH, -1); now.set(Calendar.DAY_OF_MONTH, 1); return new Date(now.getTime().getTime()); After some help of a colleague we packed the date calculations in a java class and deployed it as a jar-file it on the report server. Now I'm calling these methods as default expressions. It works perfect!! Better with JS that with iReports! If I could make a suggestion for a useful feature I would opt for a single value input control which can have a select statement to calculate a default value. Thank you very much for your great work!! Kind regards,SusannePost edited by: laloca, at: 2007/08/02 12:47 Link to comment Share on other sites More sharing options...
laloca Posted August 2, 2007 Author Share Posted August 2, 2007 Hi, Thank you all for your useful tips. After some investigations and learnings in calculating dates in Java (im not really what you would call an experiences Java developer) I realized that I can't summarize the following as a default expression: Code:Calendar now = Calendar.getInstance(); now.add(Calendar.MONTH, -1); now.set(Calendar.DAY_OF_MONTH, 1); return new Date(now.getTime().getTime()); After some help of a colleague we packed the date calculations in a java class and deployed it as a jar-file it on the report server. Now I'm calling these methods as default expressions. It works perfect!! Better with JS that with iReports! If I could make a suggestion for a useful feature I would opt for a single value input control which can have a select statement to calculate a default value. Thank you very much for your great work!! Kind regards,Susanne Link to comment Share on other sites More sharing options...
lucianc Posted August 2, 2007 Share Posted August 2, 2007 laloca wrote:If I could make a suggestion for a useful feature I would opt for a single value input control which can have a select statement to calculate a default value. You can post feature request here for JasperReports and here for JasperServer. Regards,Lucian 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