Saturday, 18 February 2012

Pentaho: Passing Parameter from JSP to Pentaho Report


Pentaho provides different API’s, which can be used in JSP pages. We can easily pass parameter from a JSP page to Pentaho reports using these APIs. Below are the steps

1. Create a .xaction file in design studio.
2. Add a Process Input as NAME.
3. The query will be as follows:

      SELECT  "EMP"."EMPNO", "EMP"."ENAME", "EMP"."SAL", "EMP"."DEPTNO"
      FROM    "EMP" where  "EMP"."ENAME"={NAME}

4. Create a HTML file with following code:

<HTML>
<BODY BGCOLOR="pink">
<br><br><br><br><br><br><br><br>
<Center>
<FORM ACTION="http://localhost:8080/pentaho/sumeet_session" METHOD=post>
ENTER YOUR NAME : <INPUT TYPE="TEXT" NAME="NAME" SIZE=20>
<P><INPUT TYPE="SUBMIT" value="Submit">
</FORM>
</center>
</BODY>
</HTML>

5. Create a JSP (sumeet_session.jsp) page with following code:

<%@ page import=
"java.util.Hashtable,
 java.util.Calendar
,java.util.Date
,java.util.Vector
,java.sql.*
,java.text.SimpleDateFormat
,javax.naming.Context
,javax.naming.InitialContext
,javax.sql.DataSource
,java.util.*" pageEncoding="UTF-8"%>
<%@ page language="java"
                import="java.util.ArrayList,
                java.util.Date,
                java.io.ByteArrayOutputStream,
                org.pentaho.platform.util.web.SimpleUrlFactory,
                org.pentaho.platform.web.jsp.messages.Messages,
                org.pentaho.platform.engine.core.system.PentahoSystem,
                org.pentaho.platform.uifoundation.chart.DashboardWidgetComponent,
                org.pentaho.platform.web.http.request.HttpRequestParameterProvider,
                org.pentaho.platform.web.http.session.HttpSessionParameterProvider,
                org.pentaho.platform.api.engine.IPentahoSession,
                org.pentaho.platform.web.http.WebTemplateHelper,
                org.pentaho.platform.util.VersionHelper,
                org.pentaho.platform.util.messages.LocaleHelper,
                org.pentaho.platform.engine.core.solution.SimpleParameterProvider,
                org.pentaho.platform.engine.services.solution.SolutionHelper,
                org.pentaho.platform.uifoundation.chart.ChartHelper,
  org.pentaho.platform.web.http.PentahoHttpSessionHelper"
                 %>

<HTML>
<BODY>
<%
   String name = request.getParameter( "NAME" );
   session.setAttribute( "NAME", name );
%>
<%
                  response.setCharacterEncoding(LocaleHelper.getSystemEncoding());
                String baseUrl = PentahoSystem.getApplicationContext().getBaseUrl();
                IPentahoSession userSession = PentahoHttpSessionHelper.getPentahoSession( request );
                  HttpRequestParameterProvider requestParameters = new HttpRequestParameterProvider( request );
                HttpSessionParameterProvider sessionParameters = new HttpSessionParameterProvider( userSession );
                SimpleParameterProvider parameters = new SimpleParameterProvider();                                           
                // pass the NAME to the report
                parameters.setParameter( "outputType", "html" );
                  parameters.setParameter( "NAME",name);                  
                // create an output stream for the report content
                ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
                ArrayList messages = new ArrayList();
                // run the action sequence 'samples/dashboard/jsp/report.xaction'
       SolutionHelper.doAction("SessionPara","","session_para.xaction","sumeet_session1.jsp",parameters,outputStream,userSession,messages, null ) // write the report content into this page
  out.write(outputStream.toString());
%>

</BODY>
</HTML>

6. Save the jsp file at following location:
biserver-ce\tomcat\webapps\pentaho\jsp

7. Make the required changes into web.xml file.
8. Run the html file.



9. Enter the name in text box and click submit button.

















    
Hope this article will make your task easier.

8 comments:

  1. This design is spectacular! You most certainly know how to keep a
    reader entertained. Between your wit and your videos, I
    was almost moved to start my own blog (well, almost.
    ..HaHa!) Great job. I really loved what you had to say, and more than that,
    how you presented it. Too cool!
    Here is my website Coupons

    ReplyDelete
  2. Very rapidly this web site will be famous amid all blogging users,
    due to it's nice posts

    Feel free to visit my web blog - cuban coffee

    ReplyDelete
  3. Hi there everyone, it's my first pay a quick visit at this web site, and paragraph is genuinely fruitful in favor of me, keep up posting such articles.

    Also visit my web-site Mascultura.pe

    ReplyDelete
  4. Cool post....!

    ReplyDelete
  5. what changes to make in web.xml file

    ReplyDelete
  6. This comment has been removed by a blog administrator.

    ReplyDelete
  7. There are so many annoying things in the http://www.faucetsmarket.com/shower-faucets-c-30.html , do not let the Pull down kitchen faucet to chaos! Smoothly with the leader, often people do not feel it's there, but mainly with its spool, Bathroom accessories, switch the way.

    ReplyDelete