Jump to content

How do you declare array parameters?


azielke

Recommended Posts

Hi all,

I'm using JasperReports 3.7.2. I'm creating a report, using the Java compiler. Now I'd like to add an IN clause using the $X{} Syntax.

My query is

select FIRST_NAME, SURNAME from test_data where $X{IN, FIRST_NAME, FIRST_NAMES}

Regarding the parameter, the JasperReports Ultimate Guide states, that "The name of the report parameter that will supply the values list. The value of this parameter can either be a java.util.Collection instance or an object or primitive Java array."

I'd like to declare my parameter FIRST_NAMES as array of java.lang.Strings. I want to do this to keep the type information of the elements, which I'd loose if I used a Collection. Therefore I tried using [Ljava.lang.String; as type, which is the way you'd obtain a String[] using reflection. This results in

net.sf.jasperreports.engine.design.JRValidationException: Report design not valid :       1. java.lang.ClassNotFoundException: [L;

When I use "java.lang.String[]", the report compiles (in iReport), but I fail to supply values for the parameter. I tried
  1. "Mack"
  2. {"Mack"}
  3. String[] {"Mack"}
  4. new java.lang.String[]{"Mack"}

All these attempts ended with an

java.lang.NoSuchMethodException: [Ljava.lang.String;.<init>(java.lang.String)      at java.lang.Class.getConstructor0(Class.java:2706) 

So, could anyone supply me with the correct way to do this?
 
Thanks.
 
Link to comment
Share on other sites

  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Thanks for the answer, but that doesn't work. When I supply

java.util.Arrays.asList(new String[]{"August", "Barbara"})

as parameter, no restriction regarding the first name is applied. Also the NoSuchMethod Exception is still thrown.

Link to comment
Share on other sites

new java.util.ArrayList(
    java.util.Arrays.asList(
        new String[] {
            "August", "Barbara"
        }
    )
)

That's what I did (except using Integer types) to pass in an array to be used as:


$X{ IN, C.ID, CityCode }

 



Post Edited by thangalin at 05/31/2010 15:02
Link to comment
Share on other sites

And your parameter is declared as String-array, or is it a List or some other Collection?

 

I'm asking because I'm declaring my parameter FIRST_NAMES as array of java.lang.Strings. I do this to keep the type information of the elements, which I'd loose if I used a Collection. I'm using the type information in my client application to generate "typed" UI widgets.

Link to comment
Share on other sites

The CityCode parameter was declared as java.util.List. The Default Value Expression was what I showed above. I may have had to do some type conversions because the data came in from a comma-delimited list in an HTML form, passed through PHP, then bridged into JasperReports.
Link to comment
Share on other sites

  • 3 months later...

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