Java – How to print the value of a map in ireport

datasourceireportjasper-reportsjava

I pass Map<String, Set<Object>> object as parameter to my ireport.
I want to print the value "Set<Object>" on the custom created group if key in the map is equal to a field.

Any Idea how to do it?
thanks in advance

HashMap<String,Object> parameters = new HashMap<String,Object>();
parameters.put("PA_CHING",retreivePaChingMapping());

public Map<String, Set<Object>> retreivePaChingMapping() {
        Map<String, Set<Object>> paChing = GenericsUtil.makeMap();
        //adds the object to paChing here 
        return paChing;
    }

In IReport:

parameter name: PA_CHING

parameter class type: java.util.HashMap

Default value expression: i don't know what to put here.

Expression of text field in ireport:

$P{paChing}.containsKey( $F{id} ) ? getChing() : "null";

private void String getChing(){
    StringBuilder ching = new StringBuilder();
    $P{PA_CHInG}.get( $F{id} ).iterator().hasNext()?ching.append($P{PA_CHING}.get( $F{id} ).iterator().next):"";

    return ching;
}

Best Answer

Put a subreport inside the group detail then in the subreport's Datasource Expression, use

new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource(new java.util.ArrayList($P{PA_CHING}.get($F{field_where_you_match_the_key})))