How to Enable Partial Page Rendering

7-6 Web User Interface Developers Guide for Oracle Application Development Framework

7.2.2 What You May Need to Know About Using the Browser Back Button

In an ADF Faces application, because some components use PPR either implicitly or because they have been configured to listen for a partial trigger, what happens when a user clicks the browser’s back button is slightly different than in an application that uses simple JSF components. In an application that uses simple JSF components, when the user clicks the browser’s back button, the browser returns the page to the state of the DOM document object model as it was when last rendered, but the state of the JavaScript is as it was when the user first entered the page. For example, suppose a user visited PageA. After the user interacts with components on the page, say a PPR event took place using JavaScript. Let’s call this new version of the page PageA1. Next, say the user navigates to PageB, then clicks the browser back button to return to PageA. The user will be shown the DOM as it was on PageA1, but the JavaScript will not have run, and therefore parts of the page will be as they were for PageA. This might mean that changes to the page will be lost. Refreshing the page will run the JavaScript and so return the user to the state it was in PageA1. In an application that uses ADF Faces, the refresh is not needed; the framework provides built-in support so that the JavaScript is run when the back button is clicked.

7.2.3 What You May Need to Know About PPR and Screen Readers

Screen readers do not reread the full page in a partial page request. PPR causes the screen reader to read the page starting from the component that fired the partial page request. You should place the target components after the component that triggers the partial request; otherwise, the screen reader would not read the updated target components.

7.3 Enabling Partial Page Rendering Programmatically

For components such as calendars that have many associated events, PPR will happen any time any event is triggered, causing any component with the calendar as a partial trigger to be rerendered with each event. If you want the target to be rerendered only for certain events, or if you want a target to be rerendered based on some other logic, you can enable partial page rendering programmatically. For example, in the ADF Faces calendar demo, if a user attempts to change the duration of an activity that no longer exists in the model, the calendar needs to be refreshed to display without the activity the calendar automatically refreshes itself if a valid activity’s duration is changed. In this example, the activityDurationChangeListener method sets the calendar as a partial target whenever the activityDurationChangeEvent is invoked, and the activity object is null. Before you begin: Create a managed bean that will contain the listener method. For more information, see Section 2.6, Creating and Using Managed Beans. Tip: You can use PPR to prevent components from being validated on a page. For more information, see Section 4.3, Using the Optimized Lifecycle. Rerendering Partial Page Content 7-7 How to enable PPR programatically: 1. In the JSF page, select the target component. In the Property Inspector, enter the set ClientComponent to true. 2. Use the binding attribute so that the managed bean can work with an instance of the target component. To do so: 1. In the Property Inspector, set the Binding to an EL expression that resolves to the target component on the managed bean. In the above example, you might set Binding to: {myBean.cal1} Where cal1 is the ID of the target component, in this case, the calendar component. 2. In the managed bean, create get and set methods for the target component. Example 7–3 shows what the code on a managed bean might look like for the calendar component. Example 7–3 Get and Set Methods for a UI Component public class MyBean { private RichCalendar cal1; public MyBean { } public void setCal1RichCalendar cal1 { this.cal1 = cal1; } public RichOutputText getCal1 { return cal1; } 3. In the managed bean, create a listener method for the event on the trigger component that should cause the target component to be rerendered. Use the addPartialTarget method to add the component using its ID as a partial target for an event, so that when that event is triggered, the partial target component is rerendered. Using this method associates the component you want to have rerendered with the event that is to trigger the rerendering. Example 7–4 shows how you might create a ActivityDurationChangeEvent listener that adds the calendar as a target. Example 7–4 Rerendering Using Partial Targets public void activityDurationChangeListenerCalendarActivityDurationChangeEvent ae { CalendarActivity activity = ae.getCalendarActivity; if activity == null { no activity with that id is found in the model Note: You must set the clientComponent attribute to true to ensure that the client ID will be generated. 7-8 Web User Interface Developers Guide for Oracle Application Development Framework System.out.printlnNo activity with event + ae.toString; setCurrActivitynull; Since the user has acted on an activity that couldnt be found, ppr the page so that they no longer see the activity RequestContext adfContext = RequestContext.getCurrentInstance; adfContext.addPartialTargetgetCal1; return; } DemoCalendarActivity demoActivity = DemoCalendarActivityactivity; TimeZone tz = getTimeZone; demoActivity.setEndDateae.getNewEndDate, tz; setCurrActivitynew DemoCalendarActivityBeandemoActivity, tz; } 4. Select the trigger component, and in the Property Inspector, find the listener for the event that will cause the refresh and bind it to the listener method created in Step 3.

7.4 Using Partial Page Navigation

Instead of performing a full page transition in the traditional way, you can configure an ADF Faces application to have navigation triggered through a partial page rendering request. The new page is sent to the client using partial page rendering. Partial page navigation is disabled by default. In order to keep track of location for example, for bookmarking purposes, or when a refresh occurs, the framework makes use of the hash portion of the URL. This portion of the URL contains the actual page being displayed in the browser.

7.4.1 How to Use Partial Page Navigation

You can turn partial page navigation on by setting the oracle.adf.view.rich.pprNavigation.OPTIONS context parameter in the web.xml file to on. To use partial page navigation: 1. Double-click the web.xml file. 2. In the source editor, change the oracle.adf.view.rich.prNavigation.OPTIONS parameter to one of the following: ■ on: Enables partial page navigation. ■ onWithForcePPR: Enables partial page navigation and notifies the framework to use the PPR channel for all action events, even those that do not result in navigation. Since partial page navigation requires that the action event be sent over PPR channel, use this option to easily enable partial page navigation. Note: If you set the parameter to on, then you need to set the partialSubmit attribute to true for any command components involved in navigation.