Showing posts with label adf. Show all posts
Showing posts with label adf. Show all posts

Wednesday, January 5, 2011

Download Jasper Report in ADF format from with ADF Taskflow

I was working on JasperReports and I had a requirement to export those reports to Pdf format. Exporting reports to Pdf by using JasperReports API is straightforward, but download it with ADF may cause an issue if you are doing it inside ADF TaskFlow.

When I google for that I found most people are doing that using Response object by setting headers


      HttpServletResponse response =(HttpServletResponse) context.getExternalContext().getResponse();
      response.setHeader("Content-Disposition", "attachment;filename=\"print.pdf\"");
      response.setContentType("application/x-download");
      OutputStream out = response.getOutputStream();
      JasperExportManager.exportReportToPdfStream(jasperPrint, out);
      context.responseComplete();

This is not working if you are using ADF Taskflow and gives the exception java.net.ProtocolException: Didn't meet stated Content-Length, wrote: '0' bytes instead of stated....; but if you are calling it from within JSPX, it will work. So what we should do with ADF Taskflow? we will do the following


      <af:commandImageLink text="My PDF Download Link"
      id="cil2">
            <af:fileDownloadActionListener contentType="application/x-download"
            filename="print.pdf"
            method="#{backingBeanScope.MyBean.downlaodReport}"/>
      </af:commandImageLink>


      public void printReport(FacesContext facesContext, OutputStream out) {
            //Export to pdf code goes here
            out.close() //close the stream
      }

I think the problem is from the way ADF TaskFlows is being rendered inside page. However best practice is to use what ADF offers which - for downloading files in this case- is  fileDownloadActionListenerOperation.

Monday, November 22, 2010

Change panelGroupLayout to use <table> instead of <div>

As most of us know that ADF by default is converting most of its containers to <div>, but sometimes there is a need to work with <table>, let us see how to do that:

It is very simple, we will use three styles  table, table-row, and table-cell. Let us suppose that we have the following ADF faces code


    <af:panelGroupLayout>
        <!-- some controls goes here -->
    </af:panelGroupLayout>
    <af:panelGroupLayout>
        <!-- some controls goes here -->
    </af:panelGroupLayout>
</af:panelGroupLayout>



We need to convert it to a table with two rows and on column, so it will be


<af:panelGroupLayout inlineStyle="display:table;">
    <af:panelGroupLayout inlineStyle="display:table-row;">
        <af:panelGroupLayout inlineStyle="display:table-cell;">
            <!-- some controls goes g -->
        </af:panelGroupLayout>
    </af:panelGroupLayout>
    <af:panelGroupLayout inlineStyle="display:table-row;">
        <af:panelGroupLayout inlineStyle="display:table-cell;">
            <!-- some controls goes g -->
        </af:panelGroupLayout>
    </af:panelGroupLayout>
</af:panelGroupLayout>



Note if you used layout property for panelGroupLayout with value equal to Horizontal, it will be converted to able but you will not have full control over it where cells will be generated automatically and you cannot add styles to them.

Wednesday, November 10, 2010

ADF: Images in CSS not displayed with IE

I am currently working on a portal project in Saudi Arabia using WebCenter. I have created my own skin and styles, and in the last days I was developing on Fedora linux so I tested my work on Firefox and Chrome. After deployment, I got surprised that images not displayed.

The issues was that I was using styles like the following:


background-image: url("../images/logo.png")repeat-x; 



but while debugging on Internet Explorer, I found that the style is not existing within the css class (not being served to Internet Explorer). To fix it, you have switch to the following


background-image: url(../images3/Center.png);
background-repeat: repeat-x;



it took from me time, to find the problem, world of css :D