Jump to content

I need help using $X for java.util.Collection parameters


hal_1

Recommended Posts

I have setup a parameter as a java.util.collection, let's call it var1

I use this in my where clause so if nothing is selected for the parameter, I will get a match.  It looks like this:

and ($X{IN,null,var1} or  $X{IN, column_1, var1})

I've been doing this for over 5 years and now it doesn't want to work when I don't select anything for the parameter.  Any ideas why?

Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

What is the deafult value in the expression for the given parameter ? 
You need to instantiate an empty array in the expression : new ArrayList(Arrays.asList()) which will give you the all effect. Select all. 
You could create another parameter that does a check if array is empty (there should be is empty method) and then use that array in your sql query to either pass a empty array or the array as is with values selected already. 

Link to comment
Share on other sites

I created a small report to demonstrate how I understand the java.collection to work.  The parameters

term_select and SelectForm_Status should both work finding any item the user selects and if they don't enter anything for the parameter, all records are returned. 

If I don't enter a valid option for the java.collection parameters, I don't find any records.

Here's the code:

<?xml version="1.0" encoding="UTF-8"?>

<!-- Created with Jaspersoft Studio version 6.5.1.final using JasperReports Library version 6.5.1  -->

<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Blank_Letter_Landscape" pageWidth="792" pageHeight="612" orientation="Landscape" columnWidth="752" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="1d7a2027-5a37-43de-a7c1-713306fb74e0">

<property name="com.jaspersoft.studio.data.sql.tables" value=""/>

<property name="com.jaspersoft.studio.data.defaultdataadapter" value="xxxxxxx"/>

<property name="ireport.jasperserver.url" value="http://xx.xx.xx.xx:8080/jasperserver/"/>

<property name="ireport.jasperserver.user" value="xxx"/>

<property name="ireport.jasperserver.reportUnit" value="/Time2Track/Administrators/Blank_Letter_Landscape"/>

<property name="ireport.jasperserver.report.resource" value="/Time2Track/Administrators/Blank_Letter_Landscape_files/main_jrxml"/>

<parameter name="school_id" class="java.lang.String"/>

<parameter name="Select_Form" class="java.lang.String"/>

<parameter name="Select_Form_Status" class="java.util.Collection" nestedType="java.lang.String" evaluationTime="Early">

<defaultValueExpression><![CDATA[new ArrayList(Arrays.asList())]]></defaultValueExpression>

</parameter>

<parameter name="term_select" class="java.util.Collection" nestedType="java.lang.String" evaluationTime="Early">

<defaultValueExpression><![CDATA[new ArrayList(Arrays.asList())]]></defaultValueExpression>

</parameter>

<parameter name="submission_start_date" class="java.util.Date"/>

<parameter name="submission_end_date" class="java.util.Date"/>

<queryString language="SQL">

<![CDATA[-- value_counts subquery

select --

form_submission_items.`form_item_id` as form_item_id, 

-- case when $Xx{IN,null,term_select} then 1 else 0 end as term_null,

"" as term_null,

form_submission_items.value as value,

case when form_submission_items.value like "%|%" then form_submission_items.value_label else form_item_values.label end as value_label,

form_submission_items.value_label as label,

count(distinct (case when form_submission_items.value in ("N/A","N/R","N/O") then null else form_submission_items.id end)) as value_count 

from form_submission_items

left join form_submission_sections on form_submission_items.`form_submission_section_id` = form_submission_sections.id

left join form_submissions on form_submission_sections.`form_submission_id` = form_submissions.id

left join practicums on practicums.id = form_submissions.practicum_id

left join form_item_values on form_submission_items.`form_item_id` = form_item_values.`form_item_id` and form_submission_items.value = form_item_values.value

left join forms on form_submissions.form_id = forms.id

where forms.school_id = $P{school_id}  

and forms.id = $P{Select_Form} 

and ($X{IN,null,Select_Form_Status} or $X{IN, form_submissions.status, Select_Form_Status})   >>>>> This is where I'm having a problem

and ($X{IN,null,term_select} or $X{IN, practicums.term_id,term_select})    >>>>> This is where I'm having a problem     I want to find all records if nothing is entered for term_select

-- and (case when $Xx{IN,null,term_select} then 1 else 0 end = 0 or $Xx{IN, practicums.term_id, term_select})

and ($P{submission_start_date} is null or date(form_submissions.requested_at) between $P{submission_start_date} and $P{submission_end_date})

and form_submission_items.`input_type` in ("radio", "checkbox","select","text_area")

group by form_item_id,value

order by form_item_id,value]]>

</queryString>

<field name="form_item_id" class="java.lang.Integer">

<property name="com.jaspersoft.studio.field.label" value="form_item_id"/>

<property name="com.jaspersoft.studio.field.tree.path" value="form_submission_items"/>

</field>

<field name="term_null" class="java.lang.String"/>

<field name="value" class="java.lang.String">

<property name="com.jaspersoft.studio.field.label" value="value"/>

<property name="com.jaspersoft.studio.field.tree.path" value="form_submission_items"/>

</field>

<field name="value_label" class="java.lang.String">

<property name="com.jaspersoft.studio.field.label" value="value_label"/>

</field>

<field name="label" class="java.lang.String">

<property name="com.jaspersoft.studio.field.label" value="label"/>

<property name="com.jaspersoft.studio.field.tree.path" value="form_submission_items"/>

</field>

<field name="value_count" class="java.lang.Long">

<property name="com.jaspersoft.studio.field.label" value="value_count"/>

</field>

<background>

<band splitType="Stretch"/>

</background>

<title>

<band splitType="Stretch"/>

</title>

<pageHeader>

<band height="11" splitType="Stretch"/>

</pageHeader>

<columnHeader>

<band height="20" splitType="Stretch">

<staticText>

<reportElement x="0" y="0" width="152" height="15" uuid="b1cc853b-3667-444c-a331-3906097e574b">

<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="11ee2ebd-abb3-40b6-b273-5a217c08af82"/>

</reportElement>

<text><![CDATA[form_item_id]]></text>

</staticText>

<staticText>

<reportElement x="152" y="0" width="150" height="15" uuid="a8bab78a-1f92-440f-9a92-edd5bfeaf88a">

<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="def49dd4-2c7c-4c2a-8345-9250be174ffc"/>

</reportElement>

<text><![CDATA[value]]></text>

</staticText>

<staticText>

<reportElement x="302" y="0" width="150" height="15" uuid="8d7e6058-5abc-49a3-8443-267ca11da29e">

<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="dc96bfc9-4581-496b-ba04-87f7650f71d1"/>

</reportElement>

<text><![CDATA[value_label]]></text>

</staticText>

<staticText>

<reportElement x="452" y="0" width="150" height="15" uuid="20eb8f99-e07d-450c-ad81-a690d13bc9d6">

<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="7ea9a36c-8ad2-4b3d-a768-a5a766220bc2"/>

</reportElement>

<text><![CDATA[label]]></text>

</staticText>

<staticText>

<reportElement x="602" y="0" width="150" height="15" uuid="f847718d-7450-42f6-9a35-e8fdc36dbbfa">

<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="af80e1f4-8c05-47e9-bb32-3ea29bfd3e86"/>

</reportElement>

<text><![CDATA[value_count]]></text>

</staticText>

</band>

</columnHeader>

<detail>

<band height="20" splitType="Stretch">

<textField>

<reportElement x="0" y="0" width="152" height="15" uuid="0ce4bcdb-83cf-44f3-a3be-796974c7699b">

<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="11ee2ebd-abb3-40b6-b273-5a217c08af82"/>

</reportElement>

<textFieldExpression><![CDATA[$F{form_item_id}]]></textFieldExpression>

</textField>

<textField>

<reportElement x="152" y="0" width="150" height="15" uuid="0f4f5d5f-a7e3-437a-bc33-063b58a5fafe">

<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="def49dd4-2c7c-4c2a-8345-9250be174ffc"/>

</reportElement>

<textFieldExpression><![CDATA[$F{value}]]></textFieldExpression>

</textField>

<textField>

<reportElement x="302" y="0" width="150" height="15" uuid="af03504d-00f2-47b2-af1a-80d00c9517bb">

<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="dc96bfc9-4581-496b-ba04-87f7650f71d1"/>

</reportElement>

<textFieldExpression><![CDATA[$F{value_label}]]></textFieldExpression>

</textField>

<textField>

<reportElement x="452" y="0" width="150" height="15" uuid="4b788aa1-cc8f-4d76-8ff3-85cf76ce756f">

<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="7ea9a36c-8ad2-4b3d-a768-a5a766220bc2"/>

</reportElement>

<textFieldExpression><![CDATA[$F{label}]]></textFieldExpression>

</textField>

<textField>

<reportElement x="602" y="0" width="150" height="15" uuid="6e60f3d6-f953-4f9c-a5f6-0ef60f71d168">

<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="af80e1f4-8c05-47e9-bb32-3ea29bfd3e86"/>

</reportElement>

<textFieldExpression><![CDATA[$F{value_count}]]></textFieldExpression>

</textField>

</band>

</detail>

<columnFooter>

<band height="21" splitType="Stretch"/>

</columnFooter>

<pageFooter>

<band height="54" splitType="Stretch"/>

</pageFooter>

<summary>

<band height="42" splitType="Stretch"/>

</summary>

</jasperReport>

 

 

Thanks,

 

Hal

Link to comment
Share on other sites

  • 2 years later...

Per community user,

Cliff Cowperthwait

I got it to work by using a subquery(highlighted): 

 It appears to be the only way to use the Collection Type in a $X{IN }

 

 

Select * from (

select distinct fgbencd_orgn_code "ORGN",

                O.ftvorgn_title "DEPARTMENT",

                fgbencd_fund_code "FUND",

                ftvfund_ftyp_code "TYPE",

                fgbencd_acct_code "ACCT",

                fgbench_num "PO",

                spriden_id "VENDORID",

                spriden_last_name "NAME",

                fgbench_estab_date "ESTABLISHED",

                sum(nvl(fgbencp_orig_encb_amt,0))  "ORIGINALENC",

                sum(nvl(fgbencp_orig_encb_amt,0)+

                    nvl(fgbencp_sum_encb_adjt,0)+

                    nvl(fgbencp_sum_encb_liq,0))  "ROLLOVERAMT"

FROM  fimsmgr.fgbench inner join fimsmgr.fgbencd on fgbencd_num = fgbench_num

                      inner join fimsmgr.fgbencp on fgbencp_num = fgbencd_num and fgbencp_item = fgbencd_item and fgbencp_seq_num = fgbencd_seq_num

                      inner join saturn.spriden  on spriden_pidm = fgbench_vendor_pidm and spriden_change_ind is null

                      inner join fimsmgr.ftvfund on ftvfund_fund_code = fgbencd_fund_code and ftvfund_eff_date = (select max(ftvfund_eff_date) from FTVFUND I where ftvfund_fund_code = fgbencd_fund_code)

                      inner join fimsmgr.ftvorgn O on O.ftvorgn_orgn_code = fgbencd_orgn_code

                                                                          and O.ftvorgn_eff_date = (select max(ftvorgn_eff_date)

                                                                                                                            from ftvorgn

                                                                                                                            where ftvorgn_orgn_code = O.ftvorgn_orgn_code

                                                                                                                        )

WHERE Substr(ltrim(fgbench_num),1,1) NOT IN ('R','E')

and   FGBENCH_STATUS_IND <> 'C'

and   FGBENCD_STATUS <> 'C'

AND   fgbench_estab_date >= '01-oct-2000'

AND   fgbench_estab_date <= '03-mar-2099'

AND   fgbencp_fsyr_code =  (SELECT substr(to_char(MAX(to_number(fofycnv(fgbencp_fsyr_code)))),3,2)

                              FROM fgbencp

                             WHERE fgbencp_num = fgbencd_num

                               AND fgbencp_item = fgbencd_item

                               AND fgbencp_seq_num = fgbencd_seq_num )

and 0 < (SELECT sum(nvl(fgbencp_orig_encb_amt,0)+

                    nvl(fgbencp_sum_encb_adjt,0)+

                    nvl(fgbencp_sum_encb_liq,0))

           FROM  fgbencp

          WHERE  fgbencp_num = fgbench_num

            AND  fgbencp_item = fgbencd_item

            AND  fgbencp_seq_num = fgbencd_seq_num

            AND  fgbencp_fsyr_code =  (SELECT substr(to_char(MAX(to_number(fofycnv(fgbencp_fsyr_code)))),3,2)

                                         FROM   fgbencp

                                        WHERE  fgbencp_num = fgbencd_num

                                          AND  fgbencp_item = fgbencd_item

                                          AND  fgbencp_seq_num = fgbencd_seq_num ))

and

1= CASE

       When $P{VENNUM} is null

       then 1

       When spriden_id like concat(concat('%' , $P{VENNUM}) , '%' )

       then 1

       else 0

       END

GROUP BY  fgbencd_orgn_code ,

          ftvorgn_title,

          fgbencd_fund_code ,

          ftvfund_ftyp_code ,

          fgbencd_acct_code ,

          fgbench_num,

          spriden_id ,

          spriden_last_name ,

          fgbench_estab_date

)

 where  $X{IN, ORGN, DEPT}

      and  $X{IN, ACCT, ACCTS}

      and  $X{IN, FUND, FUNDS}

 

Hit “READ FIELDS” and save it. The create a query List Of Values on the server to match.

 

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