Jump to content
We've recently updated our Privacy Statement, available here ×

How to pass a XML group as parameter from jasper to java


daniel.netti

Recommended Posts

I'm trying to pass a XML group content (I'm using XML as datasource) as a parameter to a java method, I need to get this group in java class, format the tags information (name1 + name2 + name3.....nameN) and return it to the JRXML TextField.
I can do it for a simple XML tag, but when I try to do it with a group, It appear as null in java method:
My XML:

    <Group1>
        <Group2>
            <Person>
            <Name>John</Name>
            </Person>
            <Person>
            <Name>Mary</Name>
            </Person>
            <Person>
            <Name>Joseph</Name>
            </Person>
        </Group2>
    </Gropup1>


My JRXML fields declaration:

    <field name="group1.group2" class="java.lang.Object">
             <fieldDescription><![CDATA[Group1/Group2]]></fieldDescription>
    </field>
    <field name="group1.group2.person" class="java.lang.Object">
             <fieldDescription><![CDATA[Group1/Group2/Person]]></fieldDescription>
    </field>
    <field name="group1.group2.person.name" class="java.lang.String">
             <fieldDescription><![CDATA[Group1/Group2/Person/Name]]></fieldDescription>
    </field>

My JRML textField Expression:

    <textFieldExpression   class="java.lang.String"><![CDATA[com.foo.report.MyReport.formatNames($F{group1.group2.person})]]></textFieldExpression>

My method signature:
    public static String formatNames(Object person) {...}

Debugging the "formatNames" method, the parameter "person" appear as null.

If I change the parameter of textFieldExpression to the field group1.group2 it appear as null too.

If I change the parameter of textFieldExpression to the field group1.group2.person.name it appear the String in the java debug: "John".

The goal is format the names list to show as: "John - Mary - Joseph" in the textFieldExpression, if someone have another way to do it, please, tell me.
Thank you

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...