coderb Posted July 1, 2008 Share Posted July 1, 2008 Hi All, After searching the forums, I can't find an answer that works for me, perhaps you could help? 1. setting default selected items for multi-select parameter. I know the input control is supposed to use the parameter default, but this does not work : <parameter name="Pay_Opt" isForPrompting="true" class="java.util.Collection"> <defaultValueExpression > <![CDATA[java.util.Arrays.asList(new java.lang.Integer[]{new java.lang.Integer(0),new java.lang.Integer(1),new java.lang.Integer(2),new java.lang.Integer(3),new java.lang.Integer(3)})]]> </defaultValueExpression> </parameter> Not sure why the input control, which I've defined with 0,1,2,3,4 as values (labels are words), is not using the above default. 2. I also have a separate input date parameter that I need the default value always to be date of last wednesday. Any pointers on how do build this expression would be greatly appreciated. thanks for any help Link to comment Share on other sites More sharing options...
lucianc Posted July 1, 2008 Share Posted July 1, 2008 coderb wrote:1. setting default selected items for multi-select parameter. Multi-valued input controls (currently) only support String values, so try to use something like java.util.Arrays.asList(new String[]{"0","1","2","3"}) as default parameter expression. I also have a separate input date parameter that I need the default value always to be date of last wednesday. You could write a utility class/method that looks something like this:Code:import java.util.Calendar;import java.util.Date;import org.apache.commons.lang.time.DateUtils;public class MyUtils { public static Date getLastDayOfWeek(int day) { Calendar date = Calendar.getInstance(); date = DateUtils.truncate(date, Calendar.DATE); if (date.get(Calendar.DAY_OF_WEEK) <= day) { date.add(Calendar.WEEK_OF_YEAR, -1); } date.set(Calendar.DAY_OF_WEEK, day); return date.getTime(); }}and then use MyUtils.getLastDayOfWeek(java.util.Calendar.WEDNESDAY) as parameter default expression. HTH,Lucian Link to comment Share on other sites More sharing options...
coderb Posted July 1, 2008 Author Share Posted July 1, 2008 Hi Lucian, once again thanks for the support. regarding the method for getting date, this is my first java attempt, so please bare with me:to test out your method/class in IReports, firstly I copied your code into a .jar file on my local directory. then, via menu option Options/ClassPath added the jar file and saved the classpath.I then edited my date parameter, adding default value expression : new MyUtils.getLastDayOfWeek(java.util.Calendar.WEDNESDAY) however, attempting to run the report returns error:it.businesslogic.ireport.gui.logpane.ProblemItem@15aba3a MyUtils.getLastDayOfWeek cannot be resolved to a type Line 27, Column 28 /jasperReport/parameter[1]/defaultValueExpression[1] exluding 'new' also results in error: it.businesslogic.ireport.gui.logpane.ProblemItem@10db6ae MyUtils cannot be resolved Line 27, Column 28 /jasperReport/parameter[1]/defaultValueExpression[1] Link to comment Share on other sites More sharing options...
lucianc Posted July 1, 2008 Share Posted July 1, 2008 coderb wrote:to test out your method/class in IReports, firstly I copied your code into a .jar file on my local directory. You need to compile the class (via javac or a Java IDE) and put compiled classes (.class file) into the jar. Regards,Lucian Link to comment Share on other sites More sharing options...
coderb Posted July 2, 2008 Author Share Posted July 2, 2008 Hi again Lucian, Sorry to ask, but having scoured the forums, and read the scriptlet chapters in the manuals, am still confused and just want to confirm the simple steps needed to get this method working. 1. I copied your code into a file called MyUtils.java and placed it in it's own directory C:utils 2. Since my local jasperserver has javac, I thought I'd just use this. So, from the command line, I changed directory to the ..jasperserver-3.0javabin and tried the compile command : javac C:utils MyUtils.java this compile failed with :----- MyUtils.java:4: package org.apache.commons.lang.time does not existimport org.apache.commons.lang.time.DateUtils; ^MyUtils.java:9: cannot find symbolsymbol : variable DateUtilslocation: class MyUtils date = DateUtils.truncate(date, Calendar.DATE); ^2 errors ------ Okay, I gathered that I need to include the classpath for org.apache.commons.lang.time in the compile args.Next problem, is trying to physcally locate the jar in which org.apache.commons.lang.time resides. There is no obvious directory or file name in my apache-tomcat installation that I can associate with org.apache.commons.lang.time. So I tried this javac -classpath C:Program Filesjasperserver-3.0apache-tomcatcommonlib -d C:java-util MyUtils.java this failed due to the space in my path name, in - 'Program Files' to I put double quotes around the full classpath I also tried replacing the space with %20 (just in case) I also tried another apache path javac -classpath "C:Program Filesjasperserver-3.0apache-tomcatbin" -d C:java-util MyUtils.java but all failed with same original error. So how do I include this class? Assuming that I get this to compile, by what I've read, it then generates a subdirectory with a .class file. How do I then 'put' that into a .jar file? Once I have a .jar file, should I move it into the ..apache-tomcatcommonclasses directory ? would that be the normal logical location for these custom classes? Once I have a compiled jar, I assume all I have to do is include it in the classpath of the report and call it as per your description. A final question - this report is going to be run a remote Mac Osx jasperserver. So, can I just upload the .jar to the jaspersever, or do I need to recompile the .java there too because of the different classpath arg used in the local javac compile? I know I'll need to change the classpath the jrxml file before uploading it to the Mac. Sorry for the long winded response, being a first timer I could not find any simple step-by-step guide to doing this. thanks for any help Link to comment Share on other sites More sharing options...
coderb Posted July 2, 2008 Author Share Posted July 2, 2008 this forum removes backslashes, so with all the paths in the post above, it doesn't read too well. Link to comment Share on other sites More sharing options...
coderb Posted July 2, 2008 Author Share Posted July 2, 2008 I found commons-lang-2.1.jar file and tried this: (note I replaced backslashes with forward slashes below - just for display purposes in this forum) javac -classpath "C:/Program Files/jasperserver-3.0/scripts/lib" -d C:/java-util MyUtils.java but unfortunately it stil returns error: MyUtils.java:4: package org.apache.commons.lang.time does not existimport org.apache.commons.lang.time.DateUtils; ^MyUtils.java:9: cannot find symbolsymbol : variable DateUtilslocation: class MyUtils date = DateUtils.truncate(date, Calendar.DATE); ^2 errors Link to comment Share on other sites More sharing options...
lucianc Posted July 2, 2008 Share Posted July 2, 2008 org.apache.commons.lang classes are located in the commons-lang jar, so you'll have to do something likeCode:javac -cp C:Program Filesjasperserver-3.0apache-tomcatwebappsjasperserverWEB-INFlibcommons-lang-2.1.jar Once you have the compile class file, you can pack it into a jar by doingCode:[code]jar cvf my-utils.jar MyUtils.class The, the simplest thing is to put the jar into ../webapps/jasperserver/WEB-INF/lib and restart the server. You can use the jar on any JasperServer instance, you won't have to recompile the source code. Regards,Lucian Link to comment Share on other sites More sharing options...
sjbotha Posted July 8, 2008 Share Posted July 8, 2008 You're missing commong-lang.jar off the end of your command. 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