Partial Page Rendering Using Hidden IFrame

By Madhusudan Pagadala

Partial page rendering removes the need for the entire Web page to be refreshed as the result of a postback. Instead, only individual regions of the page that have changed are updated, speeding up user interaction with the Web site.

Developers who want to add such features to their Web pages are often faced with a difficult decision. All of these actions can be implemented using a simple solution: by refreshing the entire page in response to the user interaction. However, this solution is easy but not always desirable. The full page refresh can be slow, giving the user the impression that the application is unresponsive.

Another option is to implement such actions using JavaScript (or other client-side scripting technologies). This results in faster response times, at the expense of more complex, less portable code. JavaScript may be a good choice for simple actions, such as updating an image, but for more complicated actions, such as scrolling through data in a table, writing custom JavaScript code can be a challenging undertaking.

This article provides a solution which avoids the drawbacks of the full page refresh and custom JavaScript solutions. In this article, partial page rendering functionality provides the ability to re-render a limited portion of a page. As in the full page render solution, partial page rendering sends a request back to the application on the middle-tier to fetch the new contents. However, when partial page rendering is used, only the modified contents are sent back to the browser. This article provides a solution using a hidden IFrame and simple JavaScript to merge the new contents back into the Web page. The end result is that the page is updated without custom JavaScript code, and without the loss of context that typically occurs with a full page refresh.

Introduction

Web pages typically support a variety of actions, such as entering and submitting form data and navigating to different pages. Many Web pages also support another type of action, which allows the user to make modifications to the contents of the Web page itself without navigating to a different page. Some examples of such actions include clicking on a link to update an image on the same page. For example, an automobile configuration application might update an image of a car as the user chooses different options, such as the preferred color.

Selecting an item from a choice box might result in modifications to other fields on the same page. For example, selecting a specific car model might update the set of available car models displayed. Clicking a link or selecting an item from a choice could be used to scroll to a new page of data in a table. Clicking a button in a table might add a new row to the table. All of these actions are similar in that they result in the same page being re-rendered in a slightly different state. Ideally, these changes should be implemented as seamlessly as possible, so that the user doesn't experience a loss of context which could distract from the task at hand.

Partial page rendering can be implemented with a simple solution using a hidden IFrame and minimal JavaScript. Any part of the page can be partially rendered with using a div or table tags in HTML.

Page Elements That May Change During PPR

  • Re-Render Data: The same fields are redrawn but their data is updated. Examples include the Refresh Data action button, or recalculate totals in a table.

  • Re-render Dependent Fields: Fields may be added, removed, or change sequence and data may be updated. Examples include the Country choice list, which may display different address fields, and toggling between Simple and Advanced Search.

  • Hide/Show Content: Both fields and data toggle in and out of view.

Page Elements That Do Not Change During PPR

Some page elements are always associated with a page, regardless of the content displayed. As a rule of thumb, elements above the page title (except message boxes) remain constant and don't change position, whereas elements in footers are constant but may move up or down the page to accommodate changes to page content. The following elements never change when PPR is initiated:

  • Branding

  • Global buttons

  • Tabs, Horizontal Navigation, SubTabs

  • Locator elements: Breadcrumbs, Train, Next/Back Locator

  • Quick links

  • Page titles (first level header)

  • Page footer

  • Separator lines between the Tabs and Page Title

In most cases the following elements don't change, other than moving up or down the page to accommodate changed elements. Nevertheless, in certain cases actions on the page may require them to be redrawn:

  • Side Navigation, unless it contains a Hide/Show control.

  • Subtabs

  • Contextual information

  • Page-level action/navigation buttons

  • Page-level Instruction text

  • Page-level Page stamps

  • Page-level Key Notation

In the above scenarios this solution can be used to achieve good performance and user interaction with the Web pages.

Contexts in Which PPR Should Not Be Used

When PPR is implemented correctly, it significantly improves application performance. When performance improvement isn't possible, it shouldn't be implemented, thus avoiding unnecessary code bloat; PPR can’t be used when navigating to another page (with a different title).

Partial Page Rendering Solution

The solution provided using simple hidden iframe and JavaScript can be used as a generalized solution to all the Partial Page Rendering scenarios.

Below is the main html (Table 1.1), which will have two buttons: one is to show a simple table which will be generated by the server, and the other button is used to remove the table.

Table 1.1

This iframe tag is used as target to the Partial Page Rendering Request. The tag:

gives the user action to get the contents of a table from the server--in this solution sample html is provided to render the table, which supposed to be generated by the server. The tag:

gives the user to remove the table from the user interface. The JavaScript:

is used to get the contents from the server, the line:

sends the GET request to the server, and as a response iframe gets the HTML.

If the requirement insists to send a POST request for Partial Page rendering Response, that can be achieved by setting the html form element target attribute as the name of hidden iframe. The code for the post request looks like:

Partial Page Rendering Server Response

Table 1.2 shows the sample response from the server for Partial Page Rendering. This response has the JavaScript code to transfer the HTML from hidden iframe to main page.

Table 1.2

The tag:

encloses the content to transfer from hidden iframe to main page.

This is the content to show the table to user. The code:

is used for triggering the action to transfer the content.

This JavaScript function does the transferring of data from the hidden iframe to main page.

This part refers to tag div html id in main page and this part:

refers the HTML of the Partial Page Response.

Conclusion

Improve the user experience with Web pages that are richer, more responsive to user actions and behave like traditional client applications. Reduce full-page refreshes and avoid page flicker. Partial page rendering using iframe is a simple solution. For more information, write to Madhusudan Pagadala.

References

  1. http://ajax.asp.net/docs/overview/PartialPageRenderingOverview.aspx

  2. http://www.w3schools.com/htmldom/dom_obj_document.asp

  3. http://www.w3schools.com/tags/tag_iframe.asp

  4. http://www.oracle.com/technology/tech/blaf/specs/ppr.html

  5. http://download-west.oracle.com/otn_hosted_doc/jdeveloper/904preview/uixhelp/uixdevguide/partialpage.html

This article originally appeared on WebReference.com.

Make a Comment

Loading Comments...

  • Web Development Newsletter Signup

    Invalid email
    You have successfuly registered to our newsletter.
  •