Programmatic Data Controls
We are going to illustrate a possibility to write a programmatic DataControl,
using an example. We are going to base this DataControl onto an LDAP repository.
When appropriate, it is possible to publish a JavaBean as a DataControl. This can be done
by a simple drag & drop from JDeveloper, and this is not what we are going
to talk about. In this example, we are going to overwrite a part of what the framework is usually
taking care of.
We will have to work on:
This class provides the interface between the future DataControl and the LDAP repository.
The source of this class can be found here.
As it can be seen in this code, there is nothing in it related to its future exposition as a DataControl.
It is just a regular JavaBean.
This class is querying the Oracle LDAP repository, and after a given filter, returns the matching rows,
made out of five columns: name, telephone number, manager ID, title, and email.
Once this class is written, we can test it from another standalone one, provided
here.
The source of this class can be found here.
This class is a JavaBean, and extends java.util.HashMap.
The get and put method
of the HashMap are overridden.
The source of this class can be found here.
This Collection of LDPAEntry's must be returned as an ArrayList.
Several important things to notice:
-
There is an important member in the class called ldapList,
it is the ArrayList we are interested in.
-
There is a method, called initialize,
that sets the required parameters for the LDAP search.
-
The method called queryCollectionFromLdap is called
from getLdapList to return the Collection we talked about earlier.
queryCollectionFromLdap is using the parameters set by the
initialize method.
The source of this class can be found here.
This is where we really begin to deal with the Framework.
This class must extend oracle.adf.model.generic.DCGenericDataControl.
Notice the constructor, invoking the super-constructor, and reading the parameters, to use them after that to
call the initialize method of the LDAPCollection class.
It can be told after the structure of the constructor, that the DataControl is based on the
LDAPCollection class.
The source of this class can be found here.
This class must extend oracle.adf.model.generic.DataControlFactoryImpl. Notice the
way the DataControl is created, and added to the framework.
Once the above classes have been written and compile correctly (the library calle "ADF Model Generic Runtime" must be part of the project),
it is time to actually put all the pieces together. This will be done through some XML files, appropriately and conveniently generated by the
IDE.
-
Right-click in the Application panel on LDAPCollection, and choose "Create DataControl" in
the contextual menu.
-
Two files are generated, one is called LDAPCollection.xml,
located next to LDapCollection.java, and
DataControls.dcx, an XML file generated in the
project default package.
-
Proceed the same way for LDAPEntry.
-
Select LDAPCollection.xml in the Application Navigator, its
structure should be displayed in the Structure Pane.
-
Select in the Structure Pane the node labeled ldapList, its parameters should be displayed
in the Property Inspector, which has to be displayed if not visible yet.
-
In the Property Inspector, you want to change the value of the parameter called BeanClass.
Mention for it the LDAPEntry, dc.ldap.model.LDAPEntry. This
means that the Collection is made out of a list of LDAPEntries.
-
Select DataControls.dcx in the Application Navigator, its
structure should be displayed in the Structure Pane.
-
In the Structure Pane, select the node labeled LDAPCollectionDataControl.
Its parameters should be displayed in the Property Inspector. In the Property Inspector is not visible,
display it, by using View | Property Inspector for example.
-
In the Property Instepctor, edit the first displayed line, which should be labeled "Factory Class",
and replace the value with the name of the one written above, dc.ldap.model.datacontrol.LDAPDataControlFactory.
After completing those steps, your LDAP DataControl should be ready to work.
In the same workspace as the DataControl we generated above, generate a new Empty Project, and make sure
to associate the "Struts" technology with it (Technology Scope in the Project Properties).
This association should generate a struts-config.xml file in your project, edit it.
- Drop a DataPage on the PageFlow diagram
- Double-click on it to generate a jsp you edit
-
From the DataBinding Palette, select the ldapList node, and drop it as a read-only form on the JSP
-
From the DataBinding Palette, the ldapList node might still be selected, drop it as navigation buttons on the JSP,
in the form generated above.
-
In the Application Pane, select in the client project the node called
DataBindings.cpx, and see its structure displayed in the Structure Pane.
-
In the Structure Pane, expand the node labeled Data Controls, and the node labeled
LDAPCollectionDataControl.
-
Right click on LDAPCollectionDataControl, and choose
"Add Parameter" from the menu.
-
Select the parameter you've just created under the Parameters node in the Structure Pane
-
In the Property Inspector,
- give it a name: FILTER
- give it a value: (sn=*stal*)
FILTER is the name of the parameter sent to the data control, its name must match what is defined
in the class called LDAPDataControl.
-
Now, go back on the Page Flow diagram, right-click on the DataPage, and run it.
-
You should see the result, and be able to navigate from record to record. Good job!
ADF Business Components