bob007 Posted April 8, 2009 Share Posted April 8, 2009 Hi all, I'm new with JasperReports, and I'm asking myself if there any way to set by parameter the field to use for a group ? And I have the same question for a textField. I will always have the same fields but I want to be able to change the grouping and one textfield specifying the field by parameter. Is it doable ? Or I have to change it programmatically when the .jxml if precompiled ? Then what is the best way to change a small part of the .jxml like that ? Thanks,Phil Link to comment Share on other sites More sharing options...
bob007 Posted April 9, 2009 Author Share Posted April 9, 2009 I tested with parameters values: - bondetravail_groupe - $F{bondetravail_groupe} - <![CDATA[$F{bondetravail_groupe}]]> The grouping are not working with the specified parameter. The textField display (in result) the string exactly like the parameter string (ex: $F{bondetravail_groupe} ) not like the value of specified field. So I guess the only way to modify the report is doing it programmaticly. To build my report with JasperDesign.I don't want to have a template (.jasper) for each grouping possibilities. Link to comment Share on other sites More sharing options...
lucianc Posted April 10, 2009 Share Posted April 10, 2009 Try this: $P{REPORT_SCRIPTLET}.getFieldValue($P{fieldNameParameter}).HTH,Lucian Link to comment Share on other sites More sharing options...
bob007 Posted April 14, 2009 Author Share Posted April 14, 2009 Hi, i tried that and it didnt work. with the value parameter value: bondetravail_noBon. <parameter name="fieldNameParameter" class="java.lang.String"> <defaultValueExpression><![CDATA[]]></defaultValueExpression> </parameter>... <field name="bondetravail_noBon" class="java.lang.String"/> ... <group name="groupe"> <groupExpression><![CDATA[$P{REPORT_SCRIPTLET}.getFieldValue( $P{fieldNameParameter} )]]></groupExpression> <groupHeader> <band height="31"> <textField isBlankWhenNull="true"> <reportElement x="1" y="11" width="187" height="20"/> <textElement> <font size="14" isBold="true"/> </textElement> <textFieldExpression class="java.lang.String"><![CDATA[$P{REPORT_SCRIPTLET}.getFieldValue( $P{fieldNameParameter} )]]></textFieldExpression> </textField> </band> </groupHeader> <groupFooter> <band height="26"/> </groupFooter> </group> Link to comment Share on other sites More sharing options...
lucianc Posted April 14, 2009 Share Posted April 14, 2009 If you add a text field that displays the same expression (the one that calls getFieldValue), does it show the correct values? Link to comment Share on other sites More sharing options...
bob007 Posted April 14, 2009 Author Share Posted April 14, 2009 No it show: nullin the textfield * ( I test it in iReport 3.5.0 ) Post Edited by Philippe Yelle at 04/14/09 16:55 Link to comment Share on other sites More sharing options...
lucianc Posted April 14, 2009 Share Posted April 14, 2009 Apparently starting from JR 3.1.4 you need to explicitly set a report scriptlet class in order to use $P{REPORT_SCRIPTLET}. So you should set net.sf.jasperreports.engine.JRDefaultScriptlet as scriptlet class for the report in order to make the expression work.Regards,Lucian Link to comment Share on other sites More sharing options...
bob007 Posted April 14, 2009 Author Share Posted April 14, 2009 Ok its near to work.Just one thing: it don't print a new group header for each group (just for the first group). Post Edited by Philippe Yelle at 04/15/09 13:11 Link to comment Share on other sites More sharing options...
lucianc Posted April 17, 2009 Share Posted April 17, 2009 Yep, that's a problem. Apparently the expressions does not work as expected when used as group expression. Let me think if there is any solution for this..Regards,Lucian Link to comment Share on other sites More sharing options...
lucianc Posted April 17, 2009 Share Posted April 17, 2009 There is a solution, which is more of a hack and not very pretty. See this thread, the part about the EvaluationScriptlet. Note that there would be a (hopefully) small performance penalty due to the fact that some time will be spent filling the exception stacktrace; perform some tests to verify that the performance does not significantly alter.HTH,LucianPost Edited by Lucian Chiriţă at 04/17/09 16:11 Link to comment Share on other sites More sharing options...
primoz Posted May 23, 2009 Share Posted May 23, 2009 Hi,I would like to have a dynamic group on a report but the group headers are not presented. I have developed my report in the iReports. I did the following steps:1.define a parameter P_GROUP_COLUMN2.modify sql statement SELECT a.name, a,surname, a.countryId, b.post FROM person a, post b WHERE a.PostId=b.PostId ORDER BY a.$P!{P_GROUP_COLUMN} (SQL is not the real one, here is just a simple example used to present table alias in order by)3.Define a new group GENERIC_GROUP <group name="GENERIC_GROUP"> <groupExpression><![CDATA[$P{REPORT_SCRIPTLET}.getFieldValue($P{P_GROUP_COLUMN})]]></groupExpression>4.Define Scriptlet class EvaluationScriptlet ( I copy the script from http://jasperforge.org/plugins/espforum/view.php?group_id=102&forumid=103&topicid=41760)Group headers are not presented in the report (only the first one). Do you have any hint what should I do? EvaluationScriptlet did not help me? Should I define something more?Regards,Primoz Link to comment Share on other sites More sharing options...
primoz Posted May 24, 2009 Share Posted May 24, 2009 Hi,I spent a few more hours today but I did not find out the way to solve the problem with dynamic groups. The simple report is in the attachment. Below is java code for EvaluationScriptlet .Regards,PrimozCode:public class EvaluationScriptlet extends JRDefaultScriptlet { public Object evaluateField(String fieldName) throws JRScriptletException { JRFillField field = (JRFillField)this.fieldsMap.get(fieldName); if (field == null) { throw new JRScriptletException("Field not found : " + fieldName); } StackTraceElement[] stack = new Exception().getStackTrace(); if (stack.length < 2) { throw new JRScriptletException("Unable to obtain current call stack"); } String evaluateMethod = stack[1].getMethodName(); Object value; if (evaluateMethod.startsWith("evaluateOld")) { value = field.getOldValue(); } else if (evaluateMethod.startsWith("evaluate")) { value = field.getValue(); } else { throw new JRScriptletException("Unable to determine evaluation type from method name " + evaluateMethod); } return value; } public String priorityDescription() throws JRScriptletException { String ls_artikelId = (String) this.getFieldValue("artikelId"); return "Does it work"+ls_artikelId; }} Link to comment Share on other sites More sharing options...
lucianc Posted May 27, 2009 Share Posted May 27, 2009 You need to use $P{REPORT_SCRIPTLET}.evaluateField($P{P_GROUP_COLUMN}) as group expression (instead of getFieldValue).Regards,Lucian Link to comment Share on other sites More sharing options...
primoz Posted May 27, 2009 Share Posted May 27, 2009 Hi Lucian!It works perfectly now. Thank you very much!Regards,Primoz Link to comment Share on other sites More sharing options...
martin.clarke Posted July 27, 2015 Share Posted July 27, 2015 Hi, 6 years on, does this apply to Studio? 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