« April 23, 2008 | Main | May 2, 2008 »

April 30, 2008 Archives

April 30, 2008

Only Rendered ADF Faces Components Can React To PPR


This question comes regularly at Oracle Support and in the forums.
You want to show (render) and hide an ADF Faces component dynamically on your page, depending on the value of another component.

Suppose f.ex. a Radio Group with 2 buttons "Show" and "Hide'.
Clicking "Show" should display a button; it should disappear when clicking "Hide".
For that, you defined a selectOneRadio that saves the values "show" and "hide" in your backing bean, in an attribute "radioBtnValue":

            <af:selectOneRadio label="Show/Hide" id="yourSelectOneRadio"
                               value="#{Backing.radioBtnValue}"
                               autoSubmit="true">
              <af:selectItem label="Show" value="show"/>
              <af:selectItem label="Hide" value="hide"/>
            </af:selectOneRadio>
You then defined your button as the following:
            <af:commandButton text="Button"
                              rendered="#{Backing.radioBtnValue=='show'}"
                              partialTriggers="yourSelectOneRadio"/>
Because of the partialTriggers property, you are expecting the button to be updated when an event occurs on the selectOneRadio.
The rendered property should then be re-evaluated and set to true when the button "Show" was clicked.

Unfortunately, it doesn't work

You cannot use PPR (Partial Page Rendering)
to directly toggle the "rendered" attribute of a component.
You have to wrap
the component (with the rendered attribute) in a parent component and set the
partialTriggers in its parent.
The reason is that only components that
are rendered can react to PPR.

In the example above, you can create a parent with the partialTriggers property, a panelGroup f.ex.:


            <af:panelGroup partialTriggers="yourSelectOneRadio">
                 <af:commandButton text="Button"
                                   rendered="#{Backing.radioBtnValue=='show'}"/>
               </af:panelGroup>

When an event occurs on the selectOneRadio, the parent component will react to PPR.
During the PPR,
the parent component and all its children will be updated.

the rendered property of the button will be evaluated and the button
displayed or hidden accordingly


I added sample 7 to my ADF Sample Applications page.


About April 2008

This page contains all entries posted to Didier's Blog in April 2008. They are listed from oldest to newest.

April 23, 2008 is the previous archive.

May 2, 2008 is the next archive.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type and Oracle