itro
itro

Reputation: 7228

How to print the value of a map in ireport?

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;
}

Upvotes: 2

Views: 9604

Answers (3)

Bnrdo
Bnrdo

Reputation: 5474

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})))

Upvotes: 1

viswanath patimalla
viswanath patimalla

Reputation: 218

Declare a new:

            Map map=(Map) parameters.get("PA_CHING");
            Set<Object> set= (Set<Object>) map.get("your key name");
            YourClass class = (YourClass) set.iterator().next();
            System.out.println(class.yourMethodName());
     System.out.println(class.yourClassVariables);

Upvotes: 0

Subba
Subba

Reputation: 406

Set.toString() will do for you.

from Javadoc

Returns a string representation of this collection. The string representation consists of a list of the collection's elements in the order they are returned by its iterator, enclosed in square brackets ("[]"). Adjacent elements are separated by the characters ", " (comma and space). Elements are converted to strings as by String.valueOf(Object).

http://docs.oracle.com/javase/6/docs/api/java/util/AbstractCollection.html#toString()

Upvotes: 0

Related Questions