0

Added more info

  1. For me JSON is the datasource.
  2. We receive JSON by hitting rest API. Rest API may need few parameters to pass.
  3. Now the parameters that API needs and jasper parameters are configured in JRXML. In below example ReportTypeList, ReportType,dateParam, SheduleDate are params configured in JRXML.SheduleDate is filter parameter to query JSON. ReportType and DateParam will be used to hit the API to get the JSON data source.

Now if you observe below for ReportTypeList they have mentioned something like defaultValueExpression in which they are trying to keep some set of values. Now I need to read this set from Java and and populate these values in a combobox on UI dynamically.

For parameter ReportType I need to get the default value if user have not selected anything from UI I need to consider the default value.

For example:

<parameter name="ReportTypeList" class="java.util.List">
    <defaultValueExpression><![CDATA[$P{ReportTypeList}.set( "Daily", "Weekly",Monthly" )]]></defaultValueExpression>
</parameter>
<parameter name="ReportType" class="java.util.List">
    <defaultValueExpression><![CDATA[$P{ReportType}.get[0]]]></defaultValueExpression>
</parameter>
<parameter name="DateParam" class="java.util.Date"/>
<parameter name="SheduleDate" class="java.util.Date"/>
1

1 Answer 1

0

When using defaultValueExpression, you need to consider that the object, class is null, so you need to instance it!

ReportTypeList - java.util.List,

$P{ReportTypeList}.set( "Daily", "Weekly",Monthly")

null.set(""), this can never work, Nullpointer and set(String,String,String) does not exists as method on java.util.List

A correct expression could be:

<parameter name="ReportTypeList" class="java.util.List">
    <defaultValueExpression><![CDATA[java.util.Arrays.asList(new String[]{"Daily", "Weekly","Monthly"})]]></defaultValueExpression>
</parameter>

ReportType - java.util.List??, probably it should be a java.lang.String

$P{ReportType}.get[0], get[0] on java.util.List, is not correct it should be .get(0) and this return's a java.lang.String, however why use an expression like this in defaultExpression, just return your String!

A correct expression could be:

<parameter name="ReportType" class="java.lang.String">
    <defaultValueExpression><![CDATA["Daily"]]></defaultValueExpression>
</parameter>

DateParam - java.util.Date

you have no defaultExpression for this, but remember you need to do something like new java.util.Date() .... and you can only use constructors present in this object!

4
  • Thank you Petter, It worked for me. One more doubt if I specified current date as default value. How I can specify date in a specific format. Jan 28, 2016 at 16:43
  • @user2728604 You like to know how to set a specific date as default value? Jan 28, 2016 at 16:44
  • Format is dd-mm-yyyy. Now when I specify new Date() as default I need data value in the specified format. Jan 29, 2016 at 8:52
  • @user2728604 the java.util.Date() will only have a format when you output it... So is this about displaying the Date or setting the Date to a value, or using it in a query? Jan 29, 2016 at 8:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.