Wednesday, June 1, 2011

Call Jasper report using a link

In previous post jasper report is called with the help of java bean. Now we can use a link to call report as in previous method calling report from a .jsff page gives error.

To call report using link follow following steps: 

  • Add a go link to page which will call servlet and also pass parameters.
  • Add a command button to assign value to parameters.
  • Add value in destination like “/jasperservlet?deptno=#{bindings.DepartmentId1.inputValue}&reporttype=#{bindings.Filetype1.inputValue}”.
  • Here deptno and reporttype are parameters passed from url and will be used in servlet.
  • To get parameter value in servlet use following code.
Integer code = Integer.valueOf(request.getParameter("deptno"));
String reporttype = request.getParameter("reporttype");

11 comments:

  1. Hi Rohit,

    I was goign through the forum post http://forums.oracle.com/forums/thread.jspa?threadID=1116145&start=15&tstart=270 on file download in jsff.

    We have to customize export to excel behavior. So i am using POI API, but as my page is jsff and in a bounded task-flow, download is not working.

    I tried writing a servlet with goLink. But how to pass Iterator Binding and other objects to that servlet? In your post it was just simple String values. But for me, i have to pull the results from iterator binding and export them to excel. As servlet is invoked as goLink, i am not able to access any scoped variable which i set before calling the servlet.

    Pls let know, if there is a way that we can pass the Iterator objects on URL while invoking the servlet..

    Thanks for your help!!

    ReplyDelete
  2. Hi Subba,

    in my application i passed the table attributes value using bindings. like deptno=#{bindings.DepartmentId1.inputValue}.

    If u want to access your table iterator in servlet pass it as a url parameter like Iterator=#{bindings.EmployeesVO1Iterator}. i didnt test that but hope will work


    Rohit

    ReplyDelete
  3. Hi Rohit,

    Thanks for your reply!!
    I tried it, but what ever we send along with URL, it takes as String, we could not pass custom JAVA objects.

    What about the solution u gave in another post "Jasper report in ADF application" in May(1), forwarding the same request to servlet, that way should we be able to attach Iterator objects to request and retrieve in servlet?

    ReplyDelete
  4. If we use the action listener and do requestDispatcher.forward() etc.... it is again same story, it is passing the object to servlet but as the button is in the context of JSFF, file download is not working.

    My main point is, why file download grammatically not working n JSFF? where it is working in JSPX

    ReplyDelete
  5. Hi subba,

    in my first post "Jasper report in ADF application" i was able to call servlet from managed bean, but that was the scenario when this managed bean function was called from a jspx page. It does not work on a jsff page that's why i did it from a go link.

    I am not sure why it is not working on a jsff page.

    ReplyDelete
  6. Hi Subba,

    I just solved the file download problem. I used the process of my 1st post "Jasper report in ADF application", in it i used a button to call the function.

    U need to do 1 more thing which is important. Use a file download listener inside button calling the function. No need to give values in the file download listener properties. Try it, works fine for me.

    Rohit

    ReplyDelete
  7. Hi Rohit,

    Thanks for your reply!!

    Did you try the calling bean method from button action listener? or file download listener under button?

    Alos, file download listener is working in JSFF? (not JSPX).. I tried in JSFF, which is in bounded task-flow. it was not working for me..

    If it is working for you, can you share sample application workspace ? It is urgent for us to resolve this issue.

    Appreciate your help in this!!

    Regards!!
    Subba.

    ReplyDelete
  8. I tried a command button and filedownloadactionlistener, which has a bean method to call POI API to create excel sheets and write to outputstream, below is sample code...

    public void OndownloadExcel(FacesContext facesContext,
    OutputStream out) {
    // Add event code here...
    try{
    DCBindingContainer bc =(DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
    JUCtrlRangeBinding tableBinding =
    (JUCtrlRangeBinding)bc.getControlBinding("CpsFacSearchVO");
    DCIteratorBinding iter = tableBinding.getIteratorBinding();
    AttributeDef[] attr = iter.getAttributeDefs((String[])tableBinding.getAttributeNames());
    //HSSFWorkbook workbook = createWorkbook(iter.getRowSetIterator(), attr, (String[])tableBinding.getAttributeNames(), iter.getEstimatedRowCount());
    System.out.println("workbook is ::::::::");
    //workbook.write(System.out);
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet("test");

    wb.write(out);

    out.flush();
    out.close();
    }catch(Exception e){
    e.printStackTrace();
    }
    }

    The button and filedownloadlistener are in JSFF which is inside bounded task-flow, which is draged as a region inside a JSPX page. The above method code is getting executed but on UI there is NO filedownload dialog coming up... it just refreshes the page..

    I tried with out filedownload listener, just calling a bean method from button action listener and from the bean method used requestDispatcher to forward the request to external servlet to download the excel file.. That is also getting executed but NO file download happening...

    If i am missing anything here, and it is working for you using JSFF(not JSPX) in bounded task-flow, pls help me with your working sample Jdev workspace.

    Thanks!!
    Subba.

    ReplyDelete
  9. Hello Subba,

    I called the bean method from button action listener and put af:filedownloadlistener under this button. No need to call Method from file download listener. That worked for me. for your information i am using jdev 11g resales 2.

    Rohit

    ReplyDelete
  10. Hi Rohit,

    Thanks for you reply!!
    Having a filedownloadlistener under command button worked for me too!!!

    However, In logs I see, below Null Pointer exception..

    java.lang.NullPointerException
    at org.apache.myfaces.trinidadinternal.taglib.listener.FileDownloadActionListener.processAction(FileDownloadActionListener.java:121)
    at oracle.adfinternal.view.faces.event.rich.FileDownloadActionListener.processAction(FileDownloadActionListener.java:77)
    at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)

    I think it is because, we did not associate any bean method to it. It is not breaking our functionality though..

    I tried having an empty bean method to it.. But then it did not work..

    ReplyDelete
  11. hi rohit,

    i tried your Jasper report in ADF aaplication it's working fine,

    but it not working in jsff. please tell me. how do it.


    I just solved the file download problem. I used the process of my 1st post "Jasper report in ADF application", in it i used a button to call the function.

    U need to do 1 more thing which is important. Use a file download listener inside button calling the function. No need to give values in the file download listener properties. Try it, works fine for me.

    if you dont mind can you give your.example,
    hereonlysubu@rediff.com

    here we are struggling with that.

    ReplyDelete