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

Trouble passing collection as parameter in execution service


erwanletutour.elt
Go to solution Solved by erwanletutour.elt,

Recommended Posts

Hello,

I have some trouble generating jasper report when i try to pass more than on value to a collection type parameter in my request body. In my rapport my parameter is decribed like this

<parameter name="skillList" class="java.util.Collection" nestedType="java.lang.String"> <parameterDescription><![CDATA[list of skill]]></parameterDescription></parameter>[/code]

In jaspersoft studio when i tried to visualize my report and add more value it work well and my report is generated
enter image description here

But when i try to use the execution service of the server using HTTP POST with a request body like this one :
 

<reportExecutionRequest>    <reportUnitUri>MyReportURI</reportUnitUri>    <async>false</async>    <outputFormat>pdf</outputFormat>    <parameters>        <reportParameter name="title">            <value>--- titre test ---</value>        </reportParameter>        <reportParameter name="header">            <value>@@@ header test @@@</value>        </reportParameter>        <reportParameter name="name">            <value>LE TUTOUR</value>        </reportParameter>        <reportParameter name="surname">            <value>Erwan</value>        </reportParameter>        <reportParameter name="skillList">                <value>java</value>                <value>maven</value>        </reportParameter>    </parameters></reportExecutionRequest>[/code]

I got an error HTTP 400, in the documentation of the service there is many exemple with more than one value so i don't understand why my repport is not generated.

EDIT

In a new attempt I changed my parameter, it's now a subdataset

<subDataset name="listSkill" uuid="8027f62e-3b29-4faf-b11a-185b4db46d6f">            <field name="skill" class="java.lang.String">                <fieldDescription><![CDATA[_THIS]]></fieldDescription>            </field></subDataset>[/code]

and the way to use it

<componentElement>   <reportElement x="0" y="200" width="100" height="30" uuid="26b52f0f-e1e0-451e-9183-2df0f1f1ce65"/>   <jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">     <datasetRun subDataset="listSkill" uuid="593d4d96-cbaf-46ba-94ef-97344e0cb4f2">       <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($P{skills}) ]]></dataSourceExpression>     </datasetRun>     <jr:listContents height="30" width="100">       <textField>         <reportElement x="0" y="0" width="100" height="30" uuid="061f84d9-205a-4f49-a711-1f657b1fa5fd"/>         <textFieldExpression><![CDATA[$F{skill}]]></textFieldExpression>       </textField>     </jr:listContents>   </jr:list> </componentElement>[/code]

but still got the same error at the generation

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

I haven't tried it, but the following article may be helpful.
https://community.jaspersoft.com/wiki/how-pass-report-parameter-values-url-multi-select-list-input-control

        <reportParameter name="skillList">                <value>java</value>                <value>maven</value>        </reportParameter>[/code]

        <reportParameter name="skillList">                <value>java</value>        </reportParameter>        <reportParameter name="skillList">                <value>maven</value>        </reportParameter>[/code]

 

Link to comment
Share on other sites

  • 2 months later...
  • Solution

Solved this:

Now I only pass 1 parameter to my rapport, a json string with all my parameters as fields.

I use a data adapter that match that string and replaced all the $P{xxxx} by $F{xxxx}.

Then I use the JSON_INPUT_STREAM parameter of the report to cast that string to byte array input stream.

In this json string, my lists object are described like this

"LIST_SKILL": [    ["skill one", "value 1"],    ["skill two", "value 2"],    ["skill three", "value 3"]]

Then on my list object, in the dataSet properties::JRDatasource expression

((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("LIST_SKILL")

After that, my report is correctly generated in jaspersoft studio / server and with rest service call.

Link to comment
Share on other sites

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...