Showing posts with label ADF showPrintablePageBehavior. Show all posts
Showing posts with label ADF showPrintablePageBehavior. Show all posts

Friday, March 20, 2020

ADF Printable view of page

Requirement-Common requirement in web application is to have printable view page for user.

How it works?

Inside adf commandlink or adf commandButton you can use <af:showPritablePageBehaviour/> tag as shown in below
<af:commandLink text="Print"
                                     id="cl2" >
                          <af:showPrintablePageBehavior  />
                         

 </af:commandLink> 

Scenario 1

if you dont want to show certain links in printable view user below render condition to hide that in printable view.



#{adfFacesContext.outputMode!='printable'}

Scenario 2

In many of the scenarios we come across requirement where we dont want to show header and footer in print preview and only jsff content should be shown in print view.
In this case

when we click on print button framework walks up the component tree, starting with the component that is the parent to the af:showPrintablePageBehavior  tag, until it reaches a panelSplitter or a panelAccordion or the root of the tree (whichever comes first). The tree is rendered from there. Additionally, certain components that are not needed in print version (such as buttons, tabs, and scrollbars) are omitted.


for example my page is having jspx with threecolumnLayout Template and inside jspx there is taskflow region as below.

when you click on print only paragraph in center should be printed or shown in print view.so trick here is to use panelSplitter inside your jsff fragment  as shown in below


my jspx code looks like below

<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
  <jsp:directive.page contentType="text/html;charset=UTF-8"/>
  <f:view>
    <af:document id="d1">
      <af:form id="f1">
        <af:pageTemplate viewId="/oracle/templates/threeColumnTemplate.jspx"
                         id="pt1">
          <f:facet name="center">
            <af:region value="#{bindings.taskflowdefinition1.regionModel}"
                       id="r1"/>
          </f:facet>
          <f:facet name="header"></f:facet>
          <f:facet name="end"></f:facet>
          <f:facet name="start">
            <af:outputText value="This is left menu"
                           inlineStyle="font-size:30px;font-weight:300;"></af:outputText>
          </f:facet>
          <f:facet name="branding"/>
          <f:facet name="copyright"/>
          <f:facet name="status"/>
        </af:pageTemplate>
      </af:form>
    </af:document>
  </f:view>

</jsp:root>

taskflowdefinition1 has jsff which looks like below


<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
          xmlns:af="http://xmlns.oracle.com/adf/faces/rich"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:c="http://java.sun.com/jsp/jstl/core"
          xmlns:h="http://java.sun.com/jsf/html">
  <af:panelSplitter orientation="horizontal" splitterPosition="0" id="ps1"
                    disabled="true" firstBorder="all" secondBorder="all"
                    dimensionsFrom="children"
                    inlineStyle="background-color:White; border-width:0px; border-style:solid; border-color:white; padding-right:0px;">
    <f:facet name="first"></f:facet>
    <f:facet name="second">
      <af:panelGroupLayout layout="vertical">
        <af:commandLink text="Print" inlineStyle="font-size:14px;"  id="cl2">
          <af:showPrintablePageBehavior/>
        </af:commandLink>
        <af:spacer height="10"></af:spacer>
        <af:panelGroupLayout>
        <af:outputText value="this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page."
                     inlineStyle="font-size:14px;"   id="ot1"/>
        <af:outputText value="this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page.this is large para for testing print preiew page."
                 inlineStyle="font-size:14px;"       id="ot2"/>
      
        </af:panelGroupLayout>
        <af:spacer height="10"></af:spacer>
          <af:commandButton text="Ok" id="cb1"/>
      </af:panelGroupLayout>
    </f:facet>
  </af:panelSplitter>

</jsp:root>

print view looks like below when clicked on print link



Conclusion :Use ADF panelspliter component to limit the print view to go further up to header and template.