# 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.

## Content

We will have to work on:

- The class that provides the features we want to access (LDAP access in our case)
- A class describing the rows returned by a query on the LDAP repository accessed by the class mentionned above
- A class gathering the rows mentionned above, as a Collection
- A class, extending the DataControl implementation
- A DataControl Factory, required by the framework
- Assembling the DataControl
- A Sample Client.

## LDAPSearch | Top

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.

## LDAPEntry | Top

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.

## LDAPCollection | Top

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.

## LDAPDataControl | Top

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.

## LDAPDataControlFactory | Top

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.

## Assembling the DataControl | Top

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.

1. Right-click in the Application panel on LDAPCollection, and choose "Create DataControl" in the contextual menu.
2. 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.
3. Proceed the same way for LDAPEntry.
4. Select LDAPCollection.xml in the Application Navigator, its structure should be displayed in the Structure Pane.
5. 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.
6. 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.
7. Select DataControls.dcx in the Application Navigator, its structure should be displayed in the Structure Pane.
8. 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.
9. 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.

## A Sample Client | Top

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.

1. Drop a DataPage on the PageFlow diagram
2. Double-click on it to generate a jsp you edit
3. From the DataBinding Palette, select the ldapList node, and drop it as a read-only form on the JSP
4. From the DataBinding Palette, the ldapList node might still be selected, drop it as navigation buttons on the JSP, in the form generated above.
5. In the Application Pane, select in the client project the node called DataBindings.cpx, and see its structure displayed in the Structure Pane.
6. In the Structure Pane, expand the node labeled Data Controls, and the node labeled LDAPCollectionDataControl.
7. Right click on LDAPCollectionDataControl, and choose "Add Parameter" from the menu.
8. Select the parameter you've just created under the Parameters node in the Structure Pane
9. 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.
10. Now, go back on the Page Flow diagram, right-click on the DataPage, and run it.
11. You should see the result, and be able to navigate from record to record. Good job!