>> More Visual Web Pack Documentation
Using JavaServer Faces Component Library to Access a LDAP Server
Contributed by Alexandre Iline, maintained by Alex Petrov and Beth Stearns
June [Revision number: V6.0] |
|
|
This tutorial shows you how to create a Visual Web project that
accesses a LDAP server. Using a LDAP JavaServer Faces (JSF) component library, which
contains a required set of nonvisual components, makes it possible to access a LDAP server. It provides instructions for downloading the LDAP component library and shows you how to create and run a sample application that relies on these LDAP components. You'll also see how everything works.
Note: When you see the term "LDAP component library" it is used as a synonym
for a "JSF component library."
|
Before you use this tutorial, you must have installed NetBeans IDE 6.0 with
Web functionality (either the Standard or Full installation) on your system, available at the
NetBeans IDE 6.0 Preview Download page.
Introduction
This tutorial illustrates how to implement a web application for requesting and diplaying data from a LDAP server. It relies on two Visual Web application projects created in NetBeans 6.0. The projects use the visual web data binding functions to connect visual components to data that data providers deliver from the LDAP server.
The LDAP browser project is a web application that holds an implementation of a data provider (LDAPTableDataProvider) as an internal Java class. In addition to data binding, the application demonstrates how to pass a request to the server and how to specify the set of attributes to be recieved from the server. The application uses JavaServer Faces components to set and display the results.
The LDAP component library project is a JavaServer Faces component library that provides a set of components for use in a NetBeans 6.0 web project. The library provides four nonvisual components—LDAPConnection, LDAPQuery, LDAPTableDataProvider, and LDAPDataProvider—which together give a web application developer flexible access to data on the LDAP server.
The LDAP component library can be installed into Netbeans and used for any visual web application. When added to a project, the components appear in the LDAP section of the Palette window in the IDE. The user can drop LDAP components from the Palette onto pages in the Design window, define properties of these components, and bind a JavaServer Faces Table component to the LDAP data provider component LDAPTableDataPropvider.
References
For further information, see the following:
- Lightweight Directory Access Protocol specification
- The LDAP Application Program Interface specification
- A Standard Data Binding and Data Access Facility for J2EE (JSR 227)
Obtaining a LDAP Component Library and Source Files
<set 3 links> You can get a LDAP component library and the source files for the component library and the browser via the following links.
- Use the link LDAP component library to download this prepared .complib-file:
LDAP_DataProviders_jdk1.5.complib
.
- Get the source files by downloading the zip file Project_LDAPComponentLibrary_sources.zip.
- Get the browser source files from the zip file Project_LDAPBrowser_sources.zip.
Setting Up a Sample Application to Use LDAP Components
Start NetBeans IDE 6.0. Select main menu item Tools -> Component Libraries and,
in the dialog that opens, click the button Import...
In the Import Component Library dialog, click the button Browse...
Then, in the file chooser select the stored file LDAP_DataProviders_jdk1.5.complib
.
|
Figure 1: Import Component Library Dialog (click image to enlarge) |
After you select the LDAP_DataProviders_jdk1.5.complib, the palette category LDAP Data Providers appears in the Import Component Library dialog. This palette category indicates the category within the Palette window where all LDAP components are placed. Click OK.
|
Figure 2: Component Library Palette Categories |
The Component Libraries dialog displays the structure of the LDAP component library. The Component List pane displays the components in the library.
Click Close to continue.
Now, create a new Visual Web project and call it LDAPSampleApp. Then, from the Projects window, right click the tree node Component Libraries
and select Add Component Library... from the context menu.
|
Figure 4: Add Component Library (click image to enlarge) |
In the Add Component Library dialog, select the list item LDAP Data Providers (1.0) and click the Add Component Library button.
|
Figure 5: Add the LDAP Library |
The LDAP component library
is added. In the Projects window, you should see a subnode LDAP Data Providers (1.0) within the Component Libraries node. Also, the Palette now includes the LDAP Data Providers category and its four LDAP components.
|
Figure 6: LDAP Component Library and LDAP Components |
Now, drag and drop the component LDAP Connection on Page1 in the Design window.
Although the Page1 display in the Design window remains empty, because all LDAP components are nonvisual, you can see a new subnode ldapConnection1 appears in the window Navigator under
the node Page1.
Notice that the Properties windows displays two properties of ldapConnection1
. The property
url
, which is the URL to an LDAP directory server, has to be defined correctly. By default, the value x500.bund.de
is assigned to this property.
|
Figure 7: LDAP Component Properties (click image to enlarge)
|
You will probably need to change the URL to the LDAP server. To change the LDAP server URL or port values, click the ellipsis button next to the property. This invokes the custom editor.
|
Figure 8: LDAP URL Custom Editor |
From the Palette, drag the component LDAP Search Query and drop it on Page1 in the Design window.
Notice that a new subnode ldapQuery1
appears in the Navigator window beneath Page1.
Click the subnode ldapQuery1
and examine its properties in the Properties window.
The property connection
must be set correctly. By default, it is assigned to an
existing ldapConnection1
. For the connection
property, use the drop-down list to change its value.
You may need to set other properties for ldapQuery1
. Click the ellipsis button to invoke the custom editor and define a value for the searchContext
property.
You can define the required search context by selecting an appropriate tree
node.
For example, if you choose the root tree node o=Bund,c=DE
(the base Naming context always shows as o=Bund,c=DE
), the search context will be o=Bund,c=DE
.
|
Figure 9: Define searchContext Property |
Similarly, invoke the custom editor to define a value of the property
resultAttributes
.
You can define the required set of result attributes by moving selected
items from the Available attributes list to the Selected attributes list.
|
Figure 10: Define the resultAttributes Property |
If you need to restrict data that is delivered by the query, you should assign an appropriate value to the property
searchFilterExpression
. To do so, you merely type an expression (for example,
cn=B*) in the values column for this property.
When you finish with these changes, the
ldapQuery1
properties are as follows:
|
Figure 11: ldapQuery1 Properties |
Now, drop the component LDAP Table DataProvider on Page1 in the Design window.
The Navigator window displays a new subnode ldapTableDataProvider1
beneath Page1.
Click the subnode ldapTableDataProvider1
and check its properties in the Properties window.
The query
property must be set to a correct value, which you choose from a drop-down list:
At this point, the only value available is ldapQuery1
.
|
Figure 12: Set the query Property |
Drop a Table component (found in the Palette window Basic category) on Page1. Right click the Table component and select Bind to Data...
from the context menu.
Using the drop-down list for the Get Data From field, change the value from defaultTableDataProvider
to ldapTableDataProvider1
.
|
Figure 13: Bind Table Component to ldapTableDataProvider1 |
The Selected list changes to display the names of LDAP query result attributes as names of table columns.
|
Figure 14: LDAP Query Result Attributes |
Page1 now looks as follows:
|
Figure 15: Final View of Page1 (click image to enlarge) |
Running the Project
The NetBeans IDE 6.0 Standard and Full installers include the Sun Java
System Application Server 9.1 technology, which is a version of
the Glassfish application server. You can deploy the project to this server in NetBeans IDE 6.0.
Click the Run->Run Main Project menu option (or the tool bar button Run Main Project shown in Figure 15) or press the F6 key.
When deployment of the application LDAPSampleApp finishes, the appropriate web page
displays in a browser:
|
Figure 16: Page1 Displayed in the Browser (click image to enlarge) |
How It Works
You can see the library source code, or rebuild it, using the link
LDAP component library sources
to download an appropriate .zip file. The zip file contains the LDAP component library project.
Extract the project from the downloaded zip fileand open it using NetBeans IDE 6.0.
|
Figure 17: Reference Problem Warning (click image to enlarge) |
Most likely, you will see a message that this project has reference problems. (The project contains a reference to a designtime.jar
file,
but at this point the file cannot be found.)
Close the warning dialog, and in the Projects window, right click the node LDAP Data Providers and
select the Resolve Reference Problems... from the context menu.
In the Resolve Reference Problems dialog, click Resolve... and, in the file chooser, select the file <NetBeans_IDE-6.0_installation_dir>/visualweb1/modules/ext/designtime.jar
.
|
Figure 18: Resolve Reference Problems Dialog |
After resolving the reference, build the project. The LDAP component library will be placed in the directory ldap_complib/complib/LDAP_DataProviders.complib
.
Summary
Creating a NetBeans 6.0 Visual Web project, which uses a JavaServer Faces component library
for accessing a LDAP server, consists of the following steps:
- Create a new project in the NetBeans 6.0 IDE.
- Add a required JavaServer Faces component library to the project.
- Add three nonvisual LDAP components to the project and properly customize their property values.
- Put a visual JSF component Table on the page in the Design window, then bind the Table to an instance of
LDAPTableDataProvider
.
- Deploy the project.
>> More NetBeans IDE 6.0 Preview Documentation
This page was last modified: June 10,