A very simple example of fetching a single property with LDAP. A JavaBean - LDAPGetProperty - is instantiated on the page. JavaScript fetches user-entered values and retrieves an attribute value from the specified directory, by setting properties on LDAPGetProperty and calling its getProperty() method.

The filter is matched to the "cn" field in a subdirectory search, unless a real filter expression is provided (e.g. uid=john*). If there is more than one match, it is considered an error and nothing is returned. On errors, the error code is retrieved, translated, and presented in an alert.

Examples of filters to test:
Paula*, S*son, *Walker
Host:
Port:
Directory base:
Filter:
Attribute:

The JavaScript code to do this is as follows:

	// Create an instance of the Bean
	getter = new netscape.ldap.beans.LDAPGetEntries();
	// Get parameters from form fields
	getter.setHost( document.input.host.value );
	getter.setPort( parseInt(document.input.port.value) );
	getter.setBase( document.input.base.value );
	filter = document.input.filter.value;
	// If the filter expression is incomplete, assume "cn="
	if ( filter.indexOf("=") == -1 )
		filter = "cn=" + filter;
	getter.setFilter( filter );
	getter.setAttribute( document.input.attribute.value );
	// Do the search
	netscape.security.PrivilegeManager.enablePrivilege("UniversalConnect");
	values = getter.getProperty();
    // Display the results, converted to a single string with line feeds
    if ( values != null ) {
        document.output.results.value=getter.convertToString( values );
    } else {
        showError();
    }