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

setting default date


Portlight

Recommended Posts

  • Replies 7
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

There are a couple of options that I would suggest:

1) Within your start/ed date parameter(s), assuming that your parameter has a class of java.util.Date, enter new Date() as the default value expression and then when you deploy the report to JasperReport Server, don't add an input control for that parameter.  Without the input control, it will always evaluate the default expression at runtime and use the current date.

2) A more elegant way would be to create another parameter that takes a string to represent the date - i.e., it could take TODAY, YESTERDAY, TOMORROW, BEGINNING OF THIS MONTH, etc.  - in addition to the actual date parameters.  When deploying to JasperReport Server you  could then create a single select list of values input control for the string parameter with the possible values of TODAY, etc. but you would not have input controls for the actual dates.  Instead, you would use the string parameter to calculate the date using your own methods/class within the default Value Expression of the date parameters by setting the Default Expression to MyClass.calculateDate($P{StringParam}).

For example, you might have a class MyClass and a static method calculateDate(String str).  This class would be deployed with the report and the method would look something like the psuedo code beow.

By doing this, you can set the String parameter to a constant value when you schedule the report and allow the report itself to calculate the actual dates relative to the actual run date/time at the time the report is running.

Code:
public static Date calculateDate(String str){     Date myDate = new Date();     if (str.equals("TODAY")) {                       myDate= new Date();     } elseif (str.equals("TODAY")) {  myDate = /*calculate the beginning of the current month */}...    return myDate;}
Link to comment
Share on other sites

Thank you for the input! I actually have a param labaled autoDate - which passes as string to the stored procedure which calculates the date based on what is passed...

I am not sure the reason my employer is requesting the startDate parameter in the actual server respository to be set to today by default. This would be something that would be server wide so not actually set in the reports.

What I have is this:

we do our reports in iReport - each report has a paramater called startDate - the value is new java.sql.Timestamp(0)

however when we import the jrxml to the JasperServer and I attach the input parameter startDate - it defaults to a date that seems to be pre-set....how do i change that preset to be today.

I am sure you have answered it and I am missing it, again thank you for helping me.

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