linuxapple Posted May 3, 2007 Share Posted May 3, 2007 Hi All, While trying to getDefaultValueExpression of parameter, I just got a class expression, which printed net.sf.jasperreports.engine.design.JRDesignExpression@d898be .What I need is default value of the parameter. Any suggestions will be greatly appreciated. Code:jasperDesign=JRXmlLoader.load(fileName); List list=jasperDesign.getParametersList(); if(list!=null){ for(int i=0;i<list.size();i++){ //System.out.println("size="+list.size()); //System.out.println("name of parameter:"+((JRParameter)list.get(i)).getName()); //System.out.println("Description of parameter:"+((JRParameter)list.get(i)).getDescription()); if(!arrParameters.contains(((JRParameter)list.get(i)).getName())){ VOParameter voparameter=new VOParameter(); voparameter.setName(((JRParameter)list.get(i)).getName()); if(((JRParameter)list.get(i)).getDefaultValueExpression()!=null){ System.out.println(((JRParameter)list.get(i)).getDefaultValueExpression()); System.out.println(((JRParameter)list.get(i)).getClass()); System.out.println(((JRParameter)list.get(i)).getValueClass()); System.out.println(((JRParameter)list.get(i)).getValueClassName()); voparameter.setDefaultValueExpression(((JRParameter)list.get(i)).getDefaultValueExpression().toString()); } voparameter.setDescription(((JRParameter)list.get(i)).getDescription()); colnAdditonalParameters.add(voparameter); b=true; } } } Thanks, Shuaibing Link to comment Share on other sites More sharing options...
schaibaa Posted May 3, 2007 Share Posted May 3, 2007 In iReport when you add a parameter you can add a default value. Be careful if you're using earlier version of java that do not support auto boxing. If that's the case, just use java 1.4 syntax to express your initial values. Link to comment Share on other sites More sharing options...
linuxapple Posted May 4, 2007 Author Share Posted May 4, 2007 Hi schaibaa, Thanks for your reply! I am really using jdk1.4 because I need to deploy my simple reporting framework(using jasperreports-1.3.1.jar) webapp on weblogic8.1, and my client wanted the software to automatically detect the default value of each parameter and pop a window for him to choose whether the default values or retyped values should be used when printing. Would you tell me exactly how to use java 1.4 syntax to express initial values? Thanks in advance! Shuaibing Link to comment Share on other sites More sharing options...
linuxapple Posted May 4, 2007 Author Share Posted May 4, 2007 Hi schaibaa, I got it! Code:(JRParameter)list.get(i)).getDefaultValueExpression().getText(); Any way, thanks again! Shuaibing Link to comment Share on other sites More sharing options...
sztgeza Posted May 5, 2007 Share Posted May 5, 2007 Hi linuxapple! But with that code, you get the epression's TEXT. E.g.you get a String Code:new Integer(5). How do you evaluate the value of this expression??? Link to comment Share on other sites More sharing options...
lucianc Posted May 17, 2007 Share Posted May 17, 2007 We've just implemented an utility class (net.sf.jasperreports.engine.fill.JRParameterDefaultValuesEvaluator) that can be used to evaluate parameter default values. You can check this out from the JasperReports SVN repository. Regards,Lucian Link to comment Share on other sites More sharing options...
martynhiemstra Posted May 31, 2007 Share Posted May 31, 2007 I was wondering, is there a class that can evaluate parameters besides their default values. I have a parameter that relies on another user supplied parameter. Is it possible to calculate that value? For example: User Parameter: MONTHParameter MONTH + 1: $P{MONTH} + 1 Link to comment Share on other sites More sharing options...
lucianc Posted May 31, 2007 Share Posted May 31, 2007 You can use JRParameterDefaultValuesEvaluator in this scenario as well. The evaluateParameterDefaultValues method takes as argument a map containing initial parameter values, so if you supply the user parameter value, the other parameter will use this value while evaluation its default value expression. HTH,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