leeyuiwah Posted January 7, 2009 Share Posted January 7, 2009 In iReport, the report parameters are java object. But how can we ask these objects to perform some object methods that return null?The only way that I know asking these objects to perform any method is in the "Default Value Expression" of the parameter. But there is a severe limitation. The java object method must returns itself (the object) -- so as to "initialize" the parameter.If this sounds too abstract, here is what I want to do.1. I can make a parameter of the type java.util.Date, let's call this $P{today}2. To get the "day" value of the Date object, the right way to do is to use java.lang.Calendar, in the following sequences:Calendar cal = Calendar.getInstance(); cal.setTime($P{today}); // setTime() method returns voidcal.get(Calendar.DATE_OF_MONTH); // get the "day" valueBut the problem is how can I fit the above steps into the iReport's model?a. As I said, the "Default Value Expression" requires that the expression returns a java object to fill up the parameter.b. If I ask cal to setTime(), it returns a type of "void"c. Can I define a function in iReport? So that I can group the above multiple statements into one function call, say getDay(), and then have this function called at the "Default Value Expression" of another parameter (e.g. $P{today_Day}).I am stuck here. Please help. Happy New Year!Clement Link to comment Share on other sites More sharing options...
hingerl Posted January 8, 2009 Share Posted January 8, 2009 hi, if you want to know the day, just use new Integer(new GregorianCalendar().get(Calendar.DAY_OF_MONTH))Post Edited by hingerl at 01/08/09 12:22 Link to comment Share on other sites More sharing options...
swood Posted January 14, 2009 Share Posted January 14, 2009 You can do this 2 ways.1. Develop a scriptlet jar with static methods that do what you want. The defaultValueExpression would then be something like: MyScriptlet.getDayOfMonth() 2. "Cascade" parameters, like:<parameter name="MyCal" class="java.util.Calendar"> <defaultValueExpression>java.util.Calendar.getInstance()</defaultValueExpression></parameter> <parameter name="DayOfMonth" class="java.lang.Integer"> <defaultValueExpression>$P{MyCal}.get(Calendar.DATE_OF_MONTH)</defaultValueExpression></parameter> ShermanJaspersoft Link to comment Share on other sites More sharing options...
leeyuiwah Posted January 14, 2009 Author Share Posted January 14, 2009 Dear Sherman,Thanks! A mystery solved! (see also Post #16497 inhttp://tinyurl.com/8nokn6)The first method works for me but not the second, because I have to setthe date of the Calendar object to a different date than today.BTW, for the record, in case someone else comes to this. Please note thatafter you created the helper class, compiled the .class and package the.jar file, you need to make the .jar file available to Jasper. If you useiReport, this means that you have to do "Tools->Options->Classpath->'AddJAR'". If you use JasperServer, you have to put the .jar under thecorrect WEB-INF/lib directory.Clement Link to comment Share on other sites More sharing options...
crax Posted January 20, 2009 Share Posted January 20, 2009 I've been trying to create a jar file to perfom what was in that older thread you posted, but I can't ever get it to work.I created a SQLUtils.java file in a text editor.Ran javac to compile it and it created a SQLUtils.class file for me.Ran jar cf SQLUtils.jar SQLUtils.class to make it a jar file and that seemed to work fine.I then added the path to the jar file in ireport from tools>options and have also put it on the report server in WEB-INF/LIBAnytime I run the report on the server or in ireport I get these errors:net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file: 1. SQLUtils cannot be resolved value = (java.lang.String)(SQLUtils.enumerate(((java.util.Collection)parameter_Sites.getValue()), true));//$JR_EXPR_ID=0$ <------> 2. SQLUtils cannot be resolved value = (java.lang.String)(SQLUtils.enumerate(((java.util.Collection)parameter_Sites.getValue()), true));//$JR_EXPR_ID=0$ <------> 3. SQLUtils cannot be resolved value = (java.lang.String)(SQLUtils.enumerate(((java.util.Collection)parameter_Sites.getValue()), true));//$JR_EXPR_ID=0$ <------> 3 errorsnet.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:1. SQLUtils cannot be resolved value = (java.lang.String)(SQLUtils.enumerate(((java.util.Collection)parameter_Sites.getValue()), true));//$JR_EXPR_ID=0$ <------>2. SQLUtils cannot be resolved value = (java.lang.String)(SQLUtils.enumerate(((java.util.Collection)parameter_Sites.getValue()), true));//$JR_EXPR_ID=0$ <------>3. SQLUtils cannot be resolved value = (java.lang.String)(SQLUtils.enumerate(((java.util.Collection)parameter_Sites.getValue()), true));//$JR_EXPR_ID=0$ <------>3 errorsPost Edited by Glen Ki at 01/20/09 19:26 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