Simple and practical usage of displaying the parameters of the Crystal Report (6) on JSP using eclipse

Source: Internet
Author: User

In many cases, you will pass some scattered data to the report, and the data is dynamic, some can be obtained from the database, and some can be customized by yourself. custom fields are not allowed for the data source of the crystal report. You can solve this problem by using parameters. You can pass the values to the corresponding parameters in the report in the background. (PS. the parameter name is case-insensitive)

// String value parameter.
String stringvalue = "My title33"; // todo: Fill in value
// The key value of the element in the hashmap variable corresponds to the name of the parameter in the report.
Hashmap map = new hashmap ();
Map. Put ("p1", stringvalue );
Map. Put ("p2", "ABx ");
Map. Put ("P3", "ABC ");

// Report Parameter Controller
Parameterfieldcontroller =
Clientdoc. getdatadefcontroller (). getparameterfieldcontroller ();
If (parameterfieldcontroller = NULL )...{

Throw new nullpointerexception ("can't get parameterfieldcontroller !! ");

}

// Iterations of the hashmap object
Iterator it = map. keyset (). iterator ();


While (it. hasnext ())...{

String key = (string) it. Next ();

Try ...{

If (! "". Equals (key) & Key! = NULL) // The following method is the most important. assign a value to the parameter.
Parameterfieldcontroller
. Setcurrentvalue ("", key. Trim (), map. Get (key ));

} Catch (reportsdkexception RDE )...{
// Handle exceptions that do not have corresponding parameters or other causes
System. Out. println ("parameter:" + key + "Throw Exception !! : "+ RDE );
}

}

My report file has two parameters: P1 and P2, without P3. Therefore, an exception is thrown. However, I do not want to display the exception information on the interface or interrupt my program, so I only display the exception information in the console.

After running, the parameters P1 and P2 in my report are successfully assigned values. The console also displays an exception for null parameters. Of course, this is because no P3 is available.

Is it very simple? This is just a small example, so it is very simple to write, but it must be improved in practical use, better encapsulation of methods, and more perfect judgment of data.

// The class used in the example. If you want to insert the following content into the Code, it is not reflected !!!!!

Java. util. hashmap,
Java. util. iterator,
Com. crystaldecisions. Reports. SDK. parameterfieldcontroller,
Com. crystaldecisions. SDK. occa. Report. Lib. reportsdkexception,
Java. Lang. nullpointerexception

(Does anyone know how to upload images in a csdn blog? Alas, it's hard to say that some things are clearly written !)

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.