christmoney1 Posted June 12, 2021 Share Posted June 12, 2021 Hello all, I need to display year on my report like that: 2020/2021This is my expression: $F{annee_entree}+"/"+ ($F{annee_entree}+1)But its don't work.There is someone who can i help me with this? Sincerely. Link to comment Share on other sites More sharing options...
yama818 Posted June 12, 2021 Share Posted June 12, 2021 If '$F{annee_entree}+"/"+ ($F{annee_entree}+1)' doesn't work, it is assumed that $F{annee_entree} is of type String.'$F{annee_entree}+"/"+ (Integer.parseInt($F{annee_entree})+1)' might work. Link to comment Share on other sites More sharing options...
christmoney1 Posted June 12, 2021 Author Share Posted June 12, 2021 Hi Yama818.Thank you very much for your help.But i've set up $F{annee_entree} as a String.This is my dataset. Link to comment Share on other sites More sharing options...
yama818 Posted June 13, 2021 Share Posted June 13, 2021 I have checked your attachment.You have defined the field type as 'java.lang.Integer'.It is indeed strange that your 'expression' does not work.The reason is that I tried it with a mock expression and it worked as expected.By the way, what values do you see in the execution result? Link to comment Share on other sites More sharing options...
christmoney1 Posted June 13, 2021 Author Share Posted June 13, 2021 Hello Thank you for your help.Yes it's strange that it does not work.This is the message error when i click on preview button: "The operator + is undefined for the argument type(s) Integer, int.".You says that you've tried with a mock expression how can i do that?Sincerely. Link to comment Share on other sites More sharing options...
yama818 Posted June 13, 2021 Share Posted June 13, 2021 The test source for me is as follows.The first text field is an example of String type.The second text field is an example of Integer type.I hope it helps.<?xml version="1.0" encoding="UTF-8"?><!-- Created with Jaspersoft Studio version 7.5.0.final using JasperReports Library version 6.11.0-0c4056ccaa4d25a5a8c45672d2f764ea3498bebb --><jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="W20210612_table" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="6fda6c7f-be6e-44f5-9943-ed910d06adb9"> <property name="com.jaspersoft.studio.data.sql.tables" value=""/> <property name="com.jaspersoft.studio.data.defaultdataadapter" value="MySQL_44_test"/> <queryString language="SQL"> <![CDATA[select 2020 year_str ,2020 year_int from dual]]> </queryString> <field name="year_str" class="java.lang.String"> <property name="com.jaspersoft.studio.field.label" value="year_str"/> </field> <field name="year_int" class="java.lang.Integer"> <property name="com.jaspersoft.studio.field.label" value="year_int"/> </field> <summary> <band height="148" splitType="Stretch"> <textField> <reportElement x="0" y="20" width="550" height="30" uuid="d8fba6e4-bc55-4bfc-ba49-f2d9a61282d8"/> <textElement> <font size="19"/> </textElement> <textFieldExpression><![CDATA[$F{year_str} + "/"+(Integer.parseInt($F{year_str})+1)]]></textFieldExpression> </textField> <textField> <reportElement x="0" y="80" width="550" height="30" uuid="6a14145e-955c-4c1f-b84e-b7224d7b3b11"/> <textElement> <font size="19"/> </textElement> <textFieldExpression><![CDATA[$F{year_int} + "/"+($F{year_int}+1)]]></textFieldExpression> </textField> </band> </summary></jasperReport> Link to comment Share on other sites More sharing options...
christmoney1 Posted June 13, 2021 Author Share Posted June 13, 2021 Hello Yama818, Its work now.I've changed on the code source the type from java.lang.Integer to java.lang.String and used on the expression (Integer.parseInt($F{annee_entree})+1)Thank you very muchRegards 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