Creating Variables and Attribute Bindings to Store Values Temporarily in the PageDef

In the last couple of weeks I often saw questions on OTN JDev & ADF Forum which I answered in a way that the problem can be solved by using a page variable to store the value e.g. from a dynamic list selection or the status of a check box.
Most users don’t use this feature which, or don’t know how to define a page variable. This post show in pictures how to do this.

Update:
It was mentioned to me that Andrejus Baranovskis did almost exactly a post like this back in 2011 (Page Definition Variables to Store Temporary Page Values). This slipped the search I did, so please take a look at Andrejus Baranovskis’s post too.

When you first create a page or a fragment there doesn’t exist a page definition file for the page:

Empty New Page

Empty New Page


If you switch to the ‘Bindings’ tab you don’t see any binding
Empty Binding

Empty Binding


The pagedef file will be created if you drag e.g. a view object from the data control onto the page or if you right click on hte page in design view and select ‘Go to Page Definition’
Create Page Def

Create Page Def


You then get this dialog which you accept with OK
Safety Dialog

Safety Dialog


Now the page def file is created. The only thing we see is the ‘variables’ in hte ‘Executables’ section
Freshly created Page Def

Freshly created Page Def


The variable iterator in the executable section is generated automatically. A quote from the docs (12.6 Working with Page Definition Files)about this iterator helps to understand how it can be used to store variables temporarily on a page:

Variable Iterator: Binds to an iterator that exposes all the variables in the binding container to the other bindings. While there is an iterator binding for each collection, there is only one variable iterator binding for all variables used on the page. (The variable iterator is like an iterator pointing to a collection that contains only one data object whose attributes are the binding container variables.)

Page variables are local to the binding container and exist only while the binding container object exists. When you use a data control method (or an operation) that requires a parameter that is to be collected from the page, JDeveloper automatically defines a variable for the parameter in the page definition file. Attribute bindings can reference the page variables.

A variable iterator can contain one of two types of variables: variable and variableUsage. A variable type variable is a simple value holder, while a variableUsage type variable is a value holder that is related to a view object’s named bind parameter. Defining a variable as a variableUsage type allows it to inherit the default value and UI control hints from the view object named bind variable to which it is bound.

Now let’s think about a use case where we can make use of the variable iterator. We can e.g. store the selection of a selectOneChoice component in a variable for later use or use a booleanCheckBox to make some other parts of the page visible.
OK, let us setup a demo page showing hoe to do this. First we define some variables in the variable iterator. We start with a Boolean variable for the checkBox to hide/show the ‘Demo Panel’.

1) right click on the variables in the executables section and choose ‘Insert Inside Variables’->’variable’

Create new Variable Inside Variable Iterator

Create new Variable Inside Variable Iterator


2) in the dialog set a name e.g. ‘toggleDisplayDemoPanel’ with type java.lang.Boolean
Define Name and Type

Define Name and Type


3) Now we define an attribute binding. Click the green ‘+’ sign in the Bindings section, select attributeValues
Add attribute Binding

Add attribute Binding


Select AttributeBinding

Select AttributeBinding


4) cklick OK to get the dialog where you select the iterator and the variable from it
Select the 'variable iterator'

Select the ‘variable iterator’


Select the Variable Name

Select the Variable Name


5) cklick OK to get the final binding
Final Binding

Final Binding


This will create a variable of type Boolean in the bindings of the page. This can be used to store the value of the booleanCheckBox component. For this select the booleanCheckBox in the page and in the property inspector we use the expression builder to set the value like we do with attributes from the data control.
In this case ‘#{bindings.toggleDisplayDemoPanel1.inputValue}’ and set the autoSubmit property to true for the checkBox
Expression Builder

Expression Builder


to show/hide the ‘Demo Panel’ we setthe same EL to the visible property of the ‘Demo Panel’ and add a partial trigger pointing to the selectBooleanCheckbox
Demo Panel

Demo Panel


Now, when we run the application
Start of Application

Start of Application


select the check box to show the panel
Showing the 'Demo Panel'

Showing the ‘Demo Panel’


One other thing we can do is to define a variable of type Integer and store the selected value of a selectOneChoice showing a dynamic lov in it. This will be shown below the selectOneChoice component. Via a button ‘Reset Selection’ the selection of the selectOneChoice can be cleared by setting the variable back to null.
Select a location from the selectOneChoice
Select a Value

Select a Value


Click the ‘Reset Selection’ button
Click 'Reset selection'

Click ‘Reset selection’


This is don without any java code by using a setPropertyListener defined on the button

        <af:commandButton text="Reset Selection" id="cb1">
          <af:setPropertyListener from="#{null}" to="#{bindings.varDepId1.inputValue}" type="action"/>
        </af:commandButton>

You can download the sample, which is using the HR DB schema, from ADF EMG Samples Project BlogVariableIterator.zip. The sample was built with JDeveloper 11.1.1.6.0

About these ads

5 thoughts on “Creating Variables and Attribute Bindings to Store Values Temporarily in the PageDef

    • Hi Andrejus, should have know that you already done this. Sorry, this slipped my search and I didn’t remebmer reading it. I’ll ptu a link to your post in hte article!
      Timo

  1. Pingback: ADF Tutorial: Implementing custom pagination. | Oralublog - Oralution's Blog

  2. Pingback: Oralution – Oracle ADF – ADF Tutorial: Implementing custom pagination.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s