I am trying to generate a jasper report using jasper server. I have uploaded the created report to server and created a parameter and an input control named roomId
When I am calling report with a value, it works. But when the roomId is null, report is empty. Means it does not even have table headers.
<parameter name="roomId" class="java.lang.Integer">
<defaultValueExpression><![CDATA[]]></defaultValueExpression>
</parameter>
<parameter name="roomIdTemp" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA[$P{roomId} == null ? "" : " AND T.ROOM_ID_01 = "+ $P{roomId} + " "]]></defaultValueExpression>
</parameter>
Calling url http://localhost:8081/jasperserver/flow.html?...... to generate report.
I am new to jasper reports. Can you please tell me whether this is illegal or not. Or am I missing anything.
I got the answer from somewhere else
I am using $P{parameterName}
It won't work if I am passing an empty string or null.
Related
I am using iReport 5.6 to design reports.
Is there any way to print report path on a bottom of the page.
I have tried with buit-in Parameters. But I actually don't know how to do this.
I want to show examples;
BaseDir: http://localhost:8080/MyReports
ReportFile: http://localhost:8080/MyReports/myreport.jasper
Thank You,
Supun
passing a parameter to the report should serve the purpose here.
String reportFileName = "your jasper path";
...
Map jasperParameters = new HashMap();
parameters.put("reportFilePath",reportFileName);
In jrxml, you will have do the following.
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports"
...>
<parameter name="reportFilePath" class="java.lang.String"/>
...
<textFieldExpression class="java.lang.String">
<![CDATA[$P{reportFilePath}]]>
</textFieldExpression>
You may refer to this example for using the parameters.
I am using iReport 4.5.1 and i need to get the date from the oracle.sql.TIMESTAMP.
Inside the expression i tried with these two:
$F{DELIVERY_DATE}.dateValue()
$F{DELIVERY_DATE}.timestampValue()
but i am getting the same runtime error
JasperReport Error:
Error filling print... Error evaluating expression :
Source text : $F{DELIVERY_DATE}.dateValue() net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression :
Source text : $F{DELIVERY_DATE}.dateValue() at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:203)
at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:591)
at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:559)
at net.sf.jasperreports.engine.fill.JRFillElement.evaluateExpression(JRFillElement.java:876)
at net.sf.jasperreports.engine.fill.JRFillTextField.evaluateText(JRFillTextField.java:421)
at net.sf.jasperreports.engine.fill.JRFillTextField.evaluate(JRFillTextField.java:406)
at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:257)
at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:473)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillBandNoOverflow(JRVerticalFiller.java:434)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillPageHeader(JRVerticalFiller.java:398)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:259)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:128)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:836)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:746)
at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:58)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:417)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:247)
at com.jaspersoft.ireport.designer.compiler.IReportCompiler.run(IReportCompiler.java:879)
at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:572)
at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:997)
Caused by: java.lang.ClassCastException: oracle.sql.TIMESTAMP cannot be cast to oracle.sql.TIMESTAMP
at Liste_colisage_par_rack_1439547941026_908820.evaluate(Liste_colisage_par_rack_1439547941026_908820:438)
at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:190)
... 19 more
Thanks in advance
Anand
Try this
In iReport, JasperReport File's XML file :
<queryString>
<![CDATA[*your query*]]>
</queryString>
<field name="DELIVERY_DATE" class="oracle.sql.TIMESTAMP"/>
<field name="NAME" class="java.lang.String"/>
Try changing it too
<queryString>
<![CDATA[*your query*]]>
</queryString>
<field name="DELIVERY_DATE" class="java.util.Date"/>
<field name="NAME" class="java.lang.String"/>
You might be using the DataType oracle.sql.TIMESTAMP from Oracle Database to JasperReport directly when you are modifying Report Query in JasperReport.
i.e. Try changing oracle.sql.TIMESTAMP to java.util.Date in your jasperReport file and use the DELIVERY_DATE Field in Jasper Report directly
NOTE:
You may have to repeatedly modify the dataType of DELIVERY_DATE to java.util.Date in XML of JasperReport if you modify the query in the Report Query section of JasperReport
This problem has been addressed here http://community.jaspersoft.com/questions/514363/oraclesqltimestamp-javasqtimestamp
for those that were led to this page searching for "oracle.sql.TIMESTAMP cannot be cast to oracle.sql.TIMESTAMP" search query - this might be occuring in other cases besides Jasper - for instance, for me, I was using my project on tomcat with ojdbc6.jar both loaded in my webapp, and in Tomcat /lib folder. The solution was to specify ojdbc6 library with "provided" scope in Maven dependencies of my webapp.
the root of the problem is given here
<parameter name="Bla" class="java.util.List" isForPrompting="false">
<defaultValueExpression><![CDATA[new ArrayList<String>() {{ add("A");}}]]></defaultValueExpression>
</parameter>
I want to see how I can populate list parameter without using java? Is that possible to do?
Error:
java.lang.NoClassDefFoundError: report_1405012032235_427203 (wrong name: report_1405012032235_427203$3)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at net.sf.jasperreports.engine.util.JRClassLoader.loadClass(JRClassLoader.java:339)
at net.sf.jasperreports.engine.util.JRClassLoader.loadClassFromBytes(JRClassLoader.java:263)
at net.sf.jasperreports.engine.design.JRAbstractJavaCompiler.loadEvaluator(JRAbstractJavaCompiler.java:102)
at net.sf.jasperreports.engine.design.JRAbstractCompiler.loadEvaluator(JRAbstractCompiler.java:340)
at net.sf.jasperreports.engine.JasperCompileManager.getEvaluator(JasperCompileManager.java:378)
at net.sf.jasperreports.engine.fill.JRFillDataset.createCalculator(JRFillDataset.java:462)
at net.sf.jasperreports.engine.fill.JRBaseFiller.<init>(JRBaseFiller.java:405)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:89)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:104)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:62)
at net.sf.jasperreports.engine.fill.JRFiller.createFiller(JRFiller.java:179)
at net.sf.jasperreports.engine.fill.BaseFillHandle.<init>(BaseFillHandle.java:75)
at net.sf.jasperreports.engine.fill.AsynchronousFillHandle.<init>(AsynchronousFillHandle.java:98)
at net.sf.jasperreports.engine.fill.AsynchronousFillHandle.<init>(AsynchronousFillHandle.java:87)
at net.sf.jasperreports.engine.fill.AsynchronousFillHandle.createHandle(AsynchronousFillHandle.java:189)
at com.jaspersoft.studio.editor.preview.view.control.ReportControler$4.run(ReportControler.java:330)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)
'report' is report name.
It only works when I don't specify inline values like:
new ArrayList<String>()
I am on Jasper Server so effectively I want to understand how do I populate the values for this kind of parameters.
I will be happy even with defaultValueExpression which creates and add values inside. If you can go beyond and show how to do rest call for report unit for such jrxml, I will award extra rep.
Try following code:
<parameter name="Bla" class="java.util.List" isForPrompting="false">
<defaultValueExpression><![CDATA[new ArrayList<String>().add(new String("A"))]]></defaultValueExpression>
</parameter>
You can initialize a list parameter using java with default expression:
<parameter name="paramName" class="java.util.List" isForPrompting="false">
<defaultValueExpression><![CDATA[Arrays.asList(new String[]{"value0","value1","value2"})]]></defaultValueExpression>
</parameter>
Note that you must add enough values as you use in the report, if not you would get an out of index exception.
Please tell me if there is any method through which I can get the user name of the user who logged into the Jasper Server, and that name could be displayed in the report.
Is there any parameter which can be referred or any other work around to obtain the logged in user name or any other way to deal with the issue.
Thanks in Advance!!
Try declaring a parameter with the name "LoggedInUsername" (this exact name, since it is reserverd by jasper to hold the username of the logged user).
<parameter name="LoggedInUsername" class="java.lang.String" isForPrompting="false"/>
and use it like $P{LoggedInUsername}.
Note: this will only work on the server, not in iReport.
Open report in iReport and create a parameter with name "LoggedInUser" and class "com.jaspersoft.jasperserver.api.metadata.user.domain.User", otherwise you can copy the below XML line in XML of the report where all parameters are listed.
<parameter name="LoggedInUser"
class="com.jaspersoft.jasperserver.api.metadata.user.domain.User"/>
Then add a text field and then you can refer to this parameter, like:
<textFieldExpression class="java.lang.String">
<![CDATA[$P{LoggedInUser}.getFullName()]]></textFieldExpression>
or
<textFieldExpression class="java.lang.String">
<![CDATA[$P{LoggedInUser}.getUsername()]]></textFieldExpression>
I have a Jasper report with a Pie Chart that is being drawn at the group_footer for my group "contract". The contract group is returning two rows at this time and I am using the contract id which are integers 1 and 3. When I print the contract id in the group_footer, it prints 1 and then 3 as expected. However, when I try and pass the same contract id into a datasetrun for the Pie Chart in the very same group_footer, the value being passed into the parameter is 3 for both charts (I am viewing the SQL using statement logging on the db server). I can not figure out how it's sending the second value "3" both times. As I mentioned, the contract id prints on the report right next to the chart as "1" the first item in the group.
Here is my subDataset with the parameter "currentContractId":
<subDataset name="age_stats" uuid="44847f01-474b-4228-96e9-ea5ab992f67b">
<property name="....data.defaultdataadapter" value="database"/>
<parameter name="currentContractId" class="...Integer" isForPrompting="false"/>
<queryString>
<![CDATA[SELECT * FROM table WHERE column = $P{currentContractId}]]>
</queryString>
<field name="age" class="java.lang.String"/>
<field name="count" class="java.lang.Long"/>
</subDataset>
Here is the chart datasetrun where I am trying to pass the field "id" into the "currentContractId" parameter for my subDataset above:
<pieDataset maxCount="6">
<dataset>
<datasetRun subDataset="age_stats" uuid="75d14f7c-f94e-4749-860f-ea95c2134e9c">
<datasetParameter name="currentContractId">
<datasetParameterExpression><![CDATA[$F{id}]]></datasetParameterExpression>
</datasetParameter>
</datasetRun>
</dataset>
</pieDataset>
I am happy to provide the full jrxml to anyone who thinks it would be helpful.
I found the problem. Aside from the options in the chart dataset wizard, there is a seperate option under the chart properties called "Evaluation Time". I set the Evaluation Time option to my Group "contract" and the problem was resolved.