Jasper Report Input Page Customization
Objective
You want to provide a parameter input page for the Jasper reports in your Windchill Business Reporting (WBR) system.
Background
The Windchill Business Reporting (WBR) solution supports reports with parameters. Windchill viewers can provide a basic input page that is presented to users to gather parameter values when the report is executed. Often times this input page requires customization for a better end user experience. For customizing input pages, use a standard Windchill Java Server Page (JSP) functionality.
Scope/Applicability/Assumptions
This documentation explains how to author a custom JSP for Jasper reports.
Assume you have access to the Windchill server JSP directory, <WindchillHome>/codebase/wtcore/jsp, to create the JSP input page <MyInputPage> in its associated sub-directory <MyInputPagePackage>.
Assume you have access rights to edit an existing Windchill Report object, <MyReport> in the Site context.
Solution
Construct and specify a custom input page for reports.
Procedure – Specifying Optional Parameters
Customization Points
Jasper reports that use Windchill Data Sources require every parameter value to be specified. However, a report can be more useful, if the user can optionally leave parameter values unspecified and the report ignores the related criteria or implicitly uses a suitable default. To achieve this behavior, it is possible to pass a parameter value consisting of a single space (“ “) and by making a single space the default value for the parameter in you input page, the user will not be required to enter anything into the parameter input field. When using this technique, you must ensure that the underlying Data Source will be able to properly handle the empty space values that are passed.
To protect the page from cross-site request forgery (CSRF) attacks, it is essential to include a hidden parameter named CSRF_NONCE. The value for this parameter can be retrieved by adding /netmarkets/jsp/cat/csrf.jspf to the input page.
Procedure – Specifying Parameters To Omit
By default, only the Data Source parameters are included in the Jasper request from Windchill. However, parameters can be explicitly excluded using the "parametersToOmit" request attribute. Note, this is a servlet request object attribute list. Assume you want to omit the parameter with name, “param1” that is in the list of parameters for the report’s Data Source. The following is an example for specifying this.
<%
request.setAttribute("parametersToOmit",
Arrays.asList("param1"));
%>
Limitations
None.
Sample Code
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@page import="java.util.Map"%>
<%@page import="java.net.URL"%>
<%@page import="java.util.HashMap"%>
<%@page import="java.util.Map.Entry"%>
<%@page import="wt.fc.ObjectReference"%>
<%@page import="wt.fc.ReferenceFactory"%>
<%@page import="com.ptc.windchill.enterprise.report.ReportHelper"%>
<%@ include file="/netmarkets/jsp/cat/csrf.jspf"%>

<%!private static void executeReport(final HttpServletRequest request, final HttpServletResponse response) throws Exception {

String oid = (String) request.getParameter("oid");
final ReferenceFactory refFactory = new ReferenceFactory();
final ObjectReference reportRef = (ObjectReference) refFactory.getReference(oid);

// Create the input parameter map(Criteria). This example uses ReportTemplate as a datasource.
String reportTemplateName = "PartReportTemplate";
Map<String, Map<String, Object>> criteriaMap = new HashMap();
Map<String, String> reportTemplateCriteria = new HashMap();
for (Entry<String, String[]> entry : request.getParameterMap().entrySet()) {
String key = entry.getKey();
String value = entry.getValue()[0];

if (key.contains(reportTemplateName)) {
reportTemplateCriteria.put(key, value);
System.out.println("Consumed key= " + key + ", value=" + value);
}
}

// Get the execution URL containing input parameters(Criteria).
final URL reportUrl = ReportHelper.manager.getThirdPartyReportExecuteUrl(reportRef, reportTemplateCriteria);
response.sendRedirect(reportUrl.toString());
return;
}
%>
<%
String partKey = request.getParameter("PartReportTemplate_stateParameter");
if(partKey!=null)
{
try {
executeReport(request, response);
} catch (Exception e) {
e.printStackTrace();
}
}%>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Demo input page</title>
</head>
<body>
<form action="#" name="mainform" id="mainform" method="post" >

<br>
<center>
<h1>
Demo Input JSP for Report: <b>DemoReportObject</b>
</h1>
</center>

<br>
<br>
<br>
<h2> Parameter for PartReportTemplate</h2>
<hr/>
<table frame="box">
<th>Parameter Name</th>
<th>Parameter Value</th>

<tr>
<td>State(upper case e,g APPROVED)</td>
<td><input type="text"
name="PartReportTemplate_stateParameter" /></td>
</tr>

</table>
<br>
<input type=hidden name="CSRF_NONCE" id ="CSRF_NONCE" value="<%=nonce%>">
<br>
<br>
<button type="submit">Generate Report</button>
</form>
</body>
</html>
Examples of Usage in Windchill Code
All of the out-of-the-box reports use Windchill JSP input pages.
Was this helpful?