ADF Code Corner: 005. How-To Bind Custom Declarative Components To ADF
ADF Code Corner: 005. How-To Bind Custom Declarative Components To ADF
twitter.com/adfcodecorner
Author:
Oracle ADF Code Corner is a loose blog-style series of how-to documents that provide solutions
to real world coding problems.
Disclaimer: All samples are provided as is with no guarantee for future upgrades or error
correction. No support can be given through Oracle customer support.
Please post questions or report problems related to the samples in this series on the OTN forum
for Oracle JDeveloper: http://forums.oracle.com/forums/forum.jspa?forumID=83
Introduction
The sample workspace built for this how-to document shows a table that updates a declarative
component whenever the row currency changes. The declarative component shows the first
name, last name and mail information of the current user. Following this how-to document and
downloading the sample workspace you learn how to create and deploy declarative components,
how to use attribute bindings to reference the current row of a table and how to enable PPR for
declarative components.
On the project root, choose New from the context menu to access the Oracle JDeveloper New Gallery.
Under the JSF node, select the JSF Declarative Component option to start the wizard that leads you
through the initial component creation.
Fill in the component template to provide a name for the component, UserInfo in this example, a file
name and package structure. The custom component is added as a tag library after deployment, which is
why you need to use the Add Tag Library button to define the library's name, namespace and prefix.
For the declarative component you can create attributes, facets and methods as needed. This can be done
later on as well using the property palette. Use attributes to pass data in from the outside to the declarative
components, which is what we use within this example. Use a facet for the application developer to be
able to add other components as child components to your declarative component. This option is useful
if your declarative component is a composite layout container you created to enforce a consistent layout
for a specific functionality in a JSF page. Similar, you use methods to map action command contained in
the declarative component to a method accessible through Expression Language on the containing page.
Once the declarative component is configured and shows in the visual editor of Oracle JDeveloper 11,
you can use the property palette to further edit or add facet definitions, attributes and methods. The
screenshot below shows the property palette as it is current in Oracle JDeveloper 11 TP4. The property
palette's look and feel will change in releases after TP4, though the exposed information remains.
For this example, I created a panel box with 3 text fields to show the user information. I could have
added a submit button to perform updates to the data as well. Selecting a text field in the visual editor - or
the structure window - allows you to use the Expression Builder from the property palette to map the
component's value property with one of the defined attributes. Any change to the attribute's value from
then on shows in the text field as its value.
Once the declarative component is done, double click onto the project node, or choose Properties from
the context menu, to open the project's properties. Choose the Deployment node to create a new
deployment profile, which you set to be of type ADF Library JAR file.
That is all what it takes to build a new declarative JavaServer Faces component, ready to be used in a web
application project. The really nice to say about declarative components is that it allows you to create
reusable building blocks for your personal application development the easy way without copy and pasting
code snippets between projects.
Following the instructions shown in the image above (Use View | Resource Palette to open the
resource catalog window), you create a new File System connection by clicking onto the Create folder
icon and choosing New Connection from the context menu.
Select the web application project and expand the File System node. It shows a sub node with the name
of the create IDE connection name. Below this node you find the deployed declarative component JAR
file entry. Select it and choose Add to Active Project from the context menu to add the library to the
current web application project.
10
Note that in this example, the user info panel appears read only, which means that no additional ADF
Faces components can be added to it. This is because the example uses attributes to pass data in, but no
facets to add nested components. If you want to allow developers to add ADF Faces components to your
declarative component, in which case your declarative component becomes the parent of the added
component, you need to add a facet to the declarative component.
11
Note that the table binding uses a single node tree binding, which is bound to the EmployesView1
iterator. Selecting a row in the table always sets this row as the current row in the underlying iterator. The
action performed for this uses partial page rendering (its doing the Ajax thing if you want to see it this
way), which means that no page reload is required for this. All that we need to wire up the declarative
component properties to the current row in the iterator is to create a "window" to the current row. This
"window" is built through attribute bindings that expose a single attribute to the binding layer.
12
After creating attribute bindings for the the FirstName, LastName and Email attribute or the ViewObject,
you are good to bind the declarative component's exposed properties to ADF. For this you use the
property palette and choose Expression Builder from the context menu (click onto the black triangle
icon).
13
It is important to node that you bind the attributes to the attribute binding's inputValue property. To use
the attribute binding itself is a frequent error among application developers that use ADF. Data is
accessed through the inputValue property of the attribute binding.
14
You can choose any layout container as a wrapper for the declarative component.
15
You can use the Edit option of the wrapper component's Partial Trigger Property to browse the page's
component tree for the component that triggers the refresh. Note that this approach is less error prone
than typing the ID reference in directly because chances are that the triggering component itself is
wrapped in a container, like panelCollection in the table case.
While you can define the ID property for the table component within this working step, note that because
of a refresh problem in Oracle JDeveloper 11 TP4, you will have to run the dialog twice to get the EL
16
This is it then. At runtime, changing the row selection in the table now will update the declarative
component.
17
18