Jump to content
Changes to the Jaspersoft community edition download ×

How to validate report parameters


neil.walker

Recommended Posts

Hello,

How do I add validation to parameters, e.g. I have a string that is requested but I want to ensure it is only numeric, or max length of 10, or not empty, etc. so when I try to run the report it stops me and shows the error?

I've also tried raising an exception in the stored procedure the reports call, but instead of a message, the report fails badly with a stack trace in Studio preview mode. I rather hoped if all else failed it would show the custom exception message rather than simply failing.

I've searched and searched the internet and the documentation and absolutely nothing comes up. Surely this is a common enough thing that should be in the documentation...

thanks for any help.

Link to comment
Share on other sites

  • Replies 7
  • Created
  • Last Reply

Top Posters In This Topic

Try this pattern on the input control. ^[0-9]{10}$

Dont use any double quotes or special characters around this pattern.

java implementation if you are interested

    public static void main(String[] args) {

        String s2 = "1234567891";
        String regnum = "^[0-9]{10}$";
        Pattern pattern2 = Pattern.compile(regnum);

        Matcher matcher2 = pattern2.matcher(s2);

        System.out.println(matcher2.matches());
         
    }

Link to comment
Share on other sites

thanks, that took some doing trying to find the 'pattern'. Seems the entire 'edit' option for a report is missing from the documentation.

But can I ask why ticking 'mandatory' on the input control shows it with an asterisk in the report but does not actually do anything, i.e. I can leave it blank and it's still happy....

Link to comment
Share on other sites

Ok, but when I enter this exactly as you put, it gives an error if the length is wrong, but on a blank entry it just allows it. Do I need to do anything else other than the pattern?

I think there's something a little flaky going on with the validation. If I change it from text to number and say the min is 1000 and the max is 9999, if I enter a number too small it gives correct answer, if I enter 1234567890 it lets it through, and if I enter any other number, e.g. 12345 I get this: There was an error on the server. Try again or contact site administrators. (Error UID: d50cf057-2dbf-41fa-8470-babbe62dbc71)

Regarding the mandatory query, I guess that's a separate question, but it doesn't seem to do anything on any input other than put a * next to the name.

 

thanks.

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