How do I display HashMap and List property in Jasper - jasper-reports

Hello All
I have a POJO class which have some property out of them two are of type
List someName;
TreeMap> myMap;
here I am getting this data from the above property and I would Like to show them on jasper report. I want to know what to write on jrxml file, I am using jasper version 1.0.2
Thanks in advance.

I don't believe you can easily display the values on a list or map using JasperReports directly from a POJO.
I believe you would have to wrap the POJO in a bean data source. See also:
http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/data/JRAbstractBeanDataSource.html
http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/data/JRBeanCollectionDataSource.html
Then, you "connect" to the bean data source and return the results as required.
This probably requires JasperReports version 3.0 or greater.

Related

How to display a simple wicket message with one simple parameter with StringResourceModel

I have one Wicket text property in the WicketApplicationProperties.properies
<entry key="dataMniejszaNizMinimalna">Wybrano datę, która jest mniejsza niż minimalna akceptowalna data '${minimalnaData}'. Nie można zapisać danych."</entry>
How to substitute a parameter {minimalnaData} with a use of a class
StringResourceModel. I don't want to create any models i want to just display a message with provided one attribute. The Wicket StringResourceModel is so complicated.
new StringResourceModel(resourceKey).setParameters(params)
how to provide this one parameter is a simplest way.
The simplest way could be:
new StringResourceModel(resourceKey, this, Model.ofMap(Map.of("minimalnaData", "some value")))
The model object could be a Java Bean or a java.util.Map.
StringResourceModel also supports java.text.MessageFormat. You can use its #setParameters() method to pass an array of values for the placeholders.
I think wicket:message should fit your need. Take a look at the wiki:
https://cwiki.apache.org/confluence/display/WICKET/Wicket%27s+XHTML+tags
You can nest components within textual content.

jasper not formatting excel data types for number properly

I was facing an issue with formats of fields having numeric values. I tried code mentioned in posts jasper not formatting excel data types
and JasperReports 5.6: JRXlsExporter.setParameter is deprecated.
But now i am facing another issue: these fields are having custom format ;;.
However when they are selected they do have right values.
I have tried both SimpleXlsReportConfiguration with xlsReportConfiguration.setDetectCellType(true); and exporter.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE);
here is the text field expression.
But both are resulting in same. Any pointers what I am missing.
JasperReports version is 5.5.2

Field not found, JRXML has definitions?

I'm using iReport Designer 5.5.0, and was making a test JRXML. I added a text field with a value of $F{pricing_date} and added "pricing_date" to the list of "fields" on the Report Inspector panel (no properties or description set for the field).
The resulting JRXML has the "pricing_date" field defined:
<field name="pricing_date" class="java.lang.String"/>
And it has a text field with $F{pricing_date} as expected:
<textFieldExpression><![CDATA[$F{pricing_date}]]></textFieldExpression>
But... I get the error "Field not found : pricing_date" within iReport, and I get the same error during compilation.
I've compared this to other JRXML files within the samples provided, and it seems to match... what am I missing? Is there a setting somewhere to recognize field definitions?
I can see two possible reasons here.
If the report does not compile, the problem might be that the element in which you have placed the textField uses a different datasource than the one in which you have declared the field.
If it does not run, you might be missing the field in the object type of the datasource. Also, if you use JRBeanCollectionDataSource from java you have to have the getter for your field (declared as getPricing_date(){...}).
Hope this helps.

Proper Case formatting a text in JasperReports

Is there a way to create a "proper case text display in JasperReports". I am using JasperReports 5.x with iReport Designer.
I have data returned from DB which is a string/text field user entered text... the problem here is some users enter in all calitals and some enter in all small I want to display the text values in a proper case... I know this can be achieved in SQL but unfortunately I dont have that option to simply edit the query....
Thanks for your help in advance...
Meeza
There wouldnt be any standard settings in iReport, you would need to use an external Method to create the text you need. I would try to go for an Apache Commons solution, or create your own Method.
I have not used the WordUtils class from Apache Commons Lang, but it looks like capitalize may be what you want.
http://commons.apache.org/proper/commons-lang/javadocs/api-2.6/org/apache/commons/lang/WordUtils.html#capitalize(java.lang.String)
To Add a Jar to your classpath in iReport:
Tools -> Option -> Classpath -> Add Jar
You then need to import the Class as well:
From the Report root element, edit the Properties. Find "Imports" click on the ellipses (...) and add your class!
iReport Imports

JasperReport 4.1.2 - Using complex Java Bean and subreports

I'm facing a problem when trying to generate a report based on some java bean's.
Suppose I have this configuration: a master bean, say
Bean1
String name
String age
ArrayList bean2
Bean2
String text
ArrayList
Bean3 is the last child of the tree and it is composed by:
String text
(I have more levels but this is enough for you to understand)
I'm using SubReport component to access data inside every ArrayList of a bean and it works well (using JRBeanCollectionDataSource()).
The problem is that, at Bean3, I have acess to all text fields of every Bean2. For example: I have an ArrayList<Bean2> of size 2: bean2_1 and bean2_2.
bean2_1 has an ArrayList<Bean3> of size 2 and bean2_2 has an ArrayList of size 3.
When I print the content of Bean3 (field text) for bean2_1 and bean2_2, it shows all 5 text values for all my beans: bean2_1 and bean2_2.
Anyone had already faced this problem? How can i bind the differente levels to show only the correct data??
Can anyone help ?