36 Using Different Output Modes

This chapter describes how you can have your pages display in modes suitable for printing and emailing. Topics include how to print page contents using the showPrintablePageBehavior tag and how to create emailable pages with the request parameter org.apache.myfaces.trinidad.agent.email=true.

This chapter includes the following sections:

36.1 Introduction to Using Different Output Modes

ADF Faces allows you to output your page in a simplified mode either for printing or for emailing. For example, you may want users to be able to print a page (or a portion of a page), but instead of printing the page exactly as it is rendered in a web browser, you want to remove items that are not needed on a printed page, such as scroll bars and buttons. If a page is to be emailed, the page must be simplified so that email clients can correctly display it.


By default, when the ADF Faces framework detects that an application is being crawled by a search engine, it outputs pages in a simplified format for the crawler, similar to that for an emailable page. If you want to generate special content for web crawlers, you can use the EL-reachable Agent interface to detect when an agent is crawling the site, and then direct the agent to a specified link, for example:
<c:if test="#{requestContext.agent.type ==  'webcrawler'}">
  <af:goLink text="This Link is rendered only for web crawlers"

For more information, see the Trinidad Javadoc.

For displaying printable pages, ADF Faces offers the showPrintablePageBehavior tag that, when used in conjunction with a command component, allows users to view a simplified version of the page in their browser, which they can then print.

For email support, ADF Faces provides an API that can be used to convert a page to one that is suitable for display in the Microsoft Outlook 2007, Mozilla Thunderbird 10.0.5, or Gmail email clients.


The current output mode (email or printable) can be reached from AdfFacesContext. Because this context is EL reachable, you can use EL to bind to the output mode from the JSP page. For example, you might allow a graphic to be rendered only if the current mode is not email using the following expression:
<af:activeImage source="/images/stockChart.gif"
              rendered="#{adfFacesContext.outputMode != "email"}"/>

You can determine the current mode using AdfFacesContext.getOutputMode().

36.2 Displaying a Page for Print

You place the showPrintablePageBehavior tag as a child to a command component. When clicked, the framework walks up the component tree, starting with the component that is the parent to the printableBehavior tag, until it reaches a panelSplitter, panelAccordion, or popup component, or the root of the tree (whichever comes first). The tree is rendered from there. Additionally, certain components that are not needed on a printed page (such as buttons and scrollbars) are omitted.

For example, in the File Explorer application, you could place a commandButton component inside the toolbar of the panelCollection component that contains the table, as shown in Figure 36-1.

Figure 36-1 Button to Print Part of a Page

Button to Print Part of a Page

When the user clicks the button, the page is displayed in a new browser window (or tab, depending on the browser) in a simplified form, as shown in Figure 36-2.

Figure 36-2 Printable Version of the Page

Printable Version of the Page

Only the contents of the table are displayed for printing. All extraneous components, such as the toolbar, buttons, and scroll bars, are not rendered.

When the button is clicked, the action event is canceled. Instead, a request is made to the server for the printable version of the page.

36.2.1 How to Use the showPrintablePageBehavior Tag

You use the showPrintablePageBehavior tag as a child to a command component.

To use the showPrintablePageBehavior tag:

  1. In one of the layout components, add a command component in the facet that contains the content you would like to print. For procedures, see Section 18.2.1, "How to Use Command Buttons and Command Links."


    While you can insert a showPrintablePageBehavior component outside of a layout component to allow the user to print the entire page, the printed result will be roughly in line with the layout, which may mean that not all content will be visible. Therefore, if you want the user to be able to print the entire content of a facet, it is important to place the command component and the showPrintablePageBehavior component within the facet whose contents users would typically want to print. If more than one facet requires printing support, then insert one command component and showPrintablePageBehavior tag into each facet. To print all contents, the user then has to execute the print command one facet at a time.
  2. In the Component Palette, from the Operations panel, drag a Show Printable Page Behavior and drop it as a child to the command component.

36.3 Creating Emailable Pages

There may be occasions when you need a page in your application to be emailed. For example, purchase orders created on the web are often emailed to the purchaser at the end of the session. However, because email clients do not support external stylesheets which are used to render to web browsers, you can't email the same page, as it would not be rendered correctly.

The ADF Faces framework provides you with automatic conversion of a JSF page so that it will render correctly in the Microsoft Outlook 2007, Mozilla Thunderbird 10.0.5, or Gmail email clients.

Not all components can be rendered in an email client. The following components can be converted so that they can render properly in an email client:

  • document

  • panelHeader

  • panelFormLayout

  • panelGroupLayout

  • panelList

  • spacer

  • showDetailHeader

  • inputText (renders as readOnly)

  • inputComboBoxListOfValues (renders as readOnly)

  • inputNumberSlider (renders as readOnly)

  • inputNumberSpinbox (renders as readOnly)

  • inputRangeSlider (renders as readOnly)

  • outputText

  • selectOneChoice (renders as readOnly)

  • panelLabelAndMessage

  • image

  • table

  • column

  • goLink (renders as text)

By default, the emailable page will display with styles inlined directly on the relevant HTML element's style attribute rather than using an internal stylesheet. You can configure this behavior by setting the web.xml parameter oracle.adf.view.DEFAULT_EMAIL_MODE to either internal or inline.

36.3.1 How to Create an Emailable Page

You notify the ADF Faces framework to convert your page to be rendered in an email client by appending the following the request parameter to the URL of the page to be emailed:


For example, say you have a page that displays a purchase order, as shown in Figure 36-3.

Figure 36-3 Purchase Order Web Page

Purchase Order Web Page

When the user clicks the Emailable Page link at the top, an actionListener method or another service appends org.apache.myfaces.trinidad.agent.email=true to the current URL and emails the page. Figure 36-4 shows the page as it appears in an email client.


By default, the framework will inline the style information onto each HTML element rather than creating an internal stylesheet. You can configure this behavior by setting the web.xml parameter oracle.adf.view.DEFAULT_EMAIL_MODE to either internal or inline. You can also force a request to render in either internal or inline mode by setting the request parameter to org.apache.myfaces.trinidad.agent.email=internal or org.apache.myfaces.trinidad.agent.email=inline.

Figure 36-4 Page in an Email Client

Page in an Email Client


If you want to be able to view the email offline, append the following request parameter to the URL of the page to be emailed:

The framework will convert the HTML to MIME (multipart/related) and inline the images so the email can be viewed offline.

36.3.2 How to Test the Rendering of a Page in an Email Client

Before you complete the development of a page, you may want to test how the page will render in an email client. You can easily do this using a goButton component.

To test an emailable page:

  1. In the Component Palette, from the Common Components panel, drag and drop a Go Button anywhere onto the page.

  2. In the Property Inspector, expand the Common section and set the Destination to be the page's name plus org.apache.myfaces.trinidad.agent.email=true.

    For example, if your page's name is myPage, the value of the destination attribute should be:

  3. Right-click the page and choose Run to run the page in the default browser.

    The Configure Default Domain dialog displays the first time your run your application and start a new domain in Integrated WebLogic Server. Use the dialog to define an administrator password for the new domain. Passwords you enter can be eight characters or more and must have a numeric character.

  4. Once the page displays in the browser, click the goButton you added to the page. This will again display the page in the browser, but converted to a page that can be handled by an email client.

  5. In your browser, view the source of the page. For example, in Mozilla Firefox, you would select View > Page Source. Select the entire source and copy it.

  6. Create a new message in your email client. Paste the page source into the message and send it to yourself.


    Because you are pasting HTML code, you will probably need to use an insert command to insert the HTML into the email body. For example, in Thunderbird, you would choose Insert > HTML.
  7. If needed, create a skin specifically for the email version of the page using an agent. The following example shows how you might specify the border on a table rendered in email.

    af|table {
      border: 1px solid #636661;
    @agent email { 
    af|table::column-resize-indicator {
      border-right: 2px dashed #979991;

    For more information about creating skins, see Chapter 20, "Customizing the Appearance Using Styles and Skins."

36.3.3 What Happens at Runtime: How ADF Faces Converts JSF Pages to Emailable Pages

When the ADF Faces framework receives the request parameter org.apache.myfaces.trinidad.agent.email=true in the Render Response phase, the associated phase listener sets an internal flag that notifies the framework to do the following:

  • Remove any JavaScript from the HTML.

  • Add all CSS to the page, but only for components included on the page and global styles (styles without the pipe character (|) in the name).

  • Remove the CSS link from the HTML.

  • Convert all relative links to absolute links.

  • Render images with absolute URLs.

  • Inline the style information onto each HTML element rather than creating an internal stylesheet.

Additionally, if you add the parameter oracle.adf.view.rich.render.emailContentType=multipart/related the framework will convert the HTML to MIME (multipart/related) and inline the images so the email can be viewed offline. The full request parameter would be: