Previous     Contents     Index     Next     
iPlanet Directory Server Resource Kit 5.1 Tools Reference



Chapter 30   Tag Library Reference


Tags are grouped in libraries according to their function. The LookMeUp application relies on the LDAP Tag Library to perform LDAP queries, a Utilities Tag Library to form queries and process responses, and the JSP Standard Tag Library (Early Access Release 1.2) for iterations and conditional operations.

This chapter provides a detailed reference of the LDAP and Utilities Tag Libraries that are only available in the iPlanet DSRK product. This information will help you customize the phone book application or develop other web-based LDAP clients.

This chapter also provides a reference for the JSP Standard Tag Library, Early Access Release 1.2, that you may use to customize the phone book application. However, if you develop new JavaServer Pages, we recommend you use the latest JSP Standard Tag Library (now known as jstl), which is slightly different. The latest release and its documentation is available from:

http://jakarta.apache.org/taglibs/doc/standard-doc/intro.html

This chapter contains the following sections:



LDAP Tag Library (ldaptl)

The LDAP Tag Library implements the interface between a JSP-enabled Web server and LDAP v3 directories. These tags represent LDAP attributes, entries, and operations, as well as the results of operations. The implementation of these tags uses the iPlanet LDAP SDK for Java to interact with any directory server.

All of the tags for performing LDAP operations have host and port attributes for specifying the directory server. Both of these attributes are optional, and when omitted, LDAP operations will use the standard port 389 on the local host.

The <ldap:add> and <ldap:modify> tags are the only ones in the LDAP Tag Library to contain other tags. The add operation defines the new entry as a set of associated <ldap:attr> tags may either be contained in the <ldap:add> tag or referenced in a variable. In a similar manner, the <ldap:modify> tag may either contain or reference <ldap:mod> tags to define individual modifications.

The LDAP operation tags will return LDAP exceptions in the variable specified in their response attribute. Check this variable to determine if an error has occurred while processing the operation. Explanations for errors may be displayed by accessing the text in the ldaperrors.properties file through a <util:prop> tag.



<ldap:add>

Add a set of attribute-value pairs as a new entry in the directory.


SYNTAX
<ldap:add [ host="hostname " port="port " ]
         user="bindDN " passwd="password "
         dn="newDN " attrs="varName " [ response="varName " ]/>

<ldap:add [ host="hostname " port="port " ]
         user="bindDN " passwd="password "
         dn="newDN " [ response="varName " ]>
   <ldap:attr ... /> ...
</ldap:add>


ATTRIBUTES



host="hostname "  

Specify the hostname of the directory server. When this attribute is omitted, the default is localhost.  

port="port "  

Specify the port number of the directory server on the given host. When this attribute is omitted, the default port is 389.  

user="bindDN "  

Specify a bind DN for accessing your directory. You must specify a bind DN that has write permission in the new DN's suffix.  

passwd="password "  

Specify the password for the bind DN. CAUTION: the password is visible in this tag, so the JSP file should be read-protected.  

dn="newDN "  

Specify the full DN of the new entry.  

attrs="varName "  

Give the name of a variable containing the set of attribute-value definitions for the new entry. When this attribute is omitted, the <ldap:add> tag must contain the <ldap:attr> definitions.  

response="varName "  

Give the name of a variable (in the PAGE scope) for storing any error response. When omitted, the default name is response.
If an LDAP error occurs during the operation, this variable will be set to the corresponding LDAPException Bean.
 



DESCRIPTION
The <ldap:add> element either references or contains a set of attribute-value pairs that will become the contents of the new entry. Attributes and their values are defined by the <ldap:attr> element.

You must define all required attributes for the new entry, including any naming attributes and objectclass attributes you wish the entry to have. If schema checking is enabled in your directory, the other attributes and their values must conform to any defined object class.


EXAMPLES
The following example shows attribute definitions referenced by the attrs attribute of the <ldap:add> element:

<ldap:attr var="attrs" scope="request"
          name="objectclass" value="top"/>
<ldap:attr var="attrs" scope="request"
          name="objectclass" value="organizationalunit"/>
<ldap:attr var="attrs" scope="request"
          name="ou" value="People"/>
<ldap:attr var="attrs" scope="request"
          name="description" value="Employee branch"/>

<ldap:add host="phonebook.siroe.com"
         user="cn=Directory Manager" passwd="password "
         dn="ou=People,dc=siroe,dc=com"
         attrs="$request:attrs" response="addError"/>

The second example creates an identical entry, but the attributes are defined within the <ldap:add> tag:

<ldap:add host="phonebook.siroe.com"
         user="cn=Directory Manager" passwd="password "
         dn="ou=People,dc=siroe,dc=com" response="addError">
   <ldap:attr name="objectclass" value="top"/>
   <ldap:attr name="objectclass" value="organizationalunit"/>
   <ldap:attr name="ou" value="People"/>
   <ldap:attr name="description" value="Employee branch"/>
</ldap:add>


SEE ALSO
<ldap:attr>



<ldap:delete>

Delete an entry from the directory.


SYNTAX
<ldap:delete [ host="hostname " port="port " ]
            user="bindDN " passwd="password "
            dn="oldDN " response="varName "/>


ATTRIBUTES



host="hostname "  

Specify the hostname of the directory server. When this attribute is omitted, the default is localhost.  

port="port "  

Specify the port number of the directory server on the given host. When this attribute is omitted, the default port is 389.  

user="bindDN "  

Specify a bind DN for accessing your directory. You must specify a bind DN that has permission to remove the given entry.  

passwd="password "  

Specify the password for the bind DN. CAUTION: the password is visible in this tag, so the JSP file should be read-protected.  

dn="oldDN "  

Specify the full DN of the entry to delete.  

response="varName "  

Give the name of a variable (in the PAGE scope) for storing any error response. When omitted, the default name is response.
If an LDAP error occurs during the operation, this variable will be set to the corresponding LDAPException Bean.
 



DESCRIPTION
Evaluating this tag will perform the LDAP delete operation on the given DN. Check the variable given by the response attribute to determine if the operation was successful.


EXAMPLE
<ldap:delete host="phonebook.siroe.com"
            user="cn=Directory Manager" passwd="password "
            dn="uid=007,ou=People,dc=siroe,dc=com"
            response="deleteError"/>



<ldap:mod>

Define a modification to a single attribute. One or more instances of this element are either contained in or referenced by the <ldap:modify> element.


SYNTAX
<ldap:mod op="add|delete|replace"
         name="attrName " [ value="valueString " ]
         [ var="varName " scope="scopeName " ]>


ATTRIBUTES



op="operation "  

Specify the type of modification to perform on the given attribute- value pair. The operation is either add, delete, or replace. When omitted, the default operation is to replace the attribute value.  

name="attrName "  

Give the name of the attribute to be modified.  

value="valueString "  

Give the new value of the attribute to be added or replaced. When deleting an attribute, either specify a particular value to remove from a multivalued attribute, or do not specify a value to remove all values and delete the attribute from the entry.  

var="varName "  

Give the name of the variable where this modification definition will be stored. The variable name and scope are not required when the <ldap:mod> tag is contained in the <ldap:modify> element.  

scope="varScope "  

Give the scope of the variable where this modification definition will be stored. When omitted, the PAGE scope is the default.  



DESCRIPTION
Each instance of this element defines a modification to perform on a single attribute of an entry. A modification may perform one of the following changes:

  • Add a new attribute and its value to the entry.

  • Replace an existing attribute's value.

  • Delete one value of a multivalued attribute.

  • Delete all values of an attribute, effectively removing it from the entry.

Use multiple instances to create a set of modifications for the <ldap:modify> tag to perform. The <ldap:modify> tag must either contain <ldap:mod> elements or reference the variable named by the var and scope attributes.


SEE ALSO
<ldap:modify> and its examples.



<ldap:modify>

Perform a set of modifications on attributes of a single entry.


SYNTAX
<ldap:modify [ host="hostname " port="port " ]
            user="bindDN " passwd="password "
            dn="targetDN " mods="varName " response="varName "/>

<ldap:modify [ host="hostname " port="port " ]
            user="bindDN " passwd="password "
            dn="targetDN " response="varName ">
   <ldap:mod ... /> ...
</ldap:modify>

<ldap:modify >


ATTRIBUTES



host="hostname "  

Specify the hostname of the directory server. When this attribute is omitted, the default is localhost.  

port="port "  

Specify the port number of the directory server on the given host. When this attribute is omitted, the default port is 389.  

user="bindDN "  

Specify a bind DN for accessing your directory. You must specify a bind DN that has write permission for the target DN.  

passwd="password "  

Specify the password for the bind DN. CAUTION: the password is visible in this tag, so the JSP file should be read-protected.  

dn="newDN "  

Specify the full DN of the target entry to be modified.  

mods="varName "  

Give the name of a variable containing the set of modifications to perform. When this attribute is omitted, the <ldap:modify> tag must contain the <ldap:mod> definitions.  

response="varName "  

Give the name of a variable (in the PAGE scope) for storing any error response. When omitted, the default name is response.
If an LDAP error occurs during the operation, this variable will be set to the corresponding LDAPException Bean.
 



DESCRIPTION
The <ldap:modify> element either references or contains a set of attribute modifications that will be performed on the target entry. Attributes may be added, replaced, or deleted, as defined in the <ldap:mod> element.

You must provide the authentication for a bind DN that has write permission on the target DN. If schema checking is enabled in your directory, new attributes or new values must conform to the object class of the target DN.

Write permission or schema errors will cause the operation to fail, which you can detect in the variable named by the response attribute.


EXAMPLES
The following example shows individual modifications that are referenced by the mods attribute of the <ldap:modify> element:

<ldap:mod var="mods" scope="request"
         op="replace" name="postalAddress"
         value="123 Main Street"/>

<ldap:mod var="mods" scope="request"
         op="replace" name="facsimileTelephoneNumber"
         value="408 555 1234"/>

<ldap:mod var="mods" scope="request"
         op="delete" name="telephoneNumber"
         value="407 555 9876"/>

<ldap:mod var="mods" scope="request"
         op="add" name="telephoneNumber"
         value="408 555 6789"/>

<ldap:modify host="phonebook.siroe.com"
            user="cn=Directory Manager" passwd="password "
            dn="uid=6,ou=People,dc=siroe,dc=com">
            mods="$request:mods" response="modifyError/>

The second example performs the same operation, but the modifications are defined within the <ldap:add> tag. Note that the default modification is to replace an attribute value, so the op attribute may be omitted:

<ldap:modify host="phonebook.siroe.com"
            user="cn=Directory Manager" passwd="password "
            dn="uid=6,ou=People,dc=siroe,dc=com"
            response="modifyError">
   <ldap:mod name="postalAddress" value="123 Main Street"/>
   <ldap:mod name="facsimileTelephoneNumber" value="408 555 1234"/>
   <ldap:mod op="delete" name="telephoneNumber"
            value="407 555 9876"/>
   <ldap:mod op="add" name="telephoneNumber"
            value="408 555 6789"/>
</ldap:modify>


SEE ALSO
<ldap:mod>



<ldap:search>

Performs an LDAP search and returns the set of resulting entries. This element is an iterator that will evaluate its contents for every entry in the search results.


SYNTAX
<ldap:search [ host="hostname " port="port " ]
            [ user="bindDN " passwd="password " ]
            base="baseDN " [ srchScope="base|one|sub" ]
            [ filter="filterString " attrs="attrList " ]
            [ maxEntries="number " controls="beanName " ]
            [ entry="iterName " response="varName " ]>
   <... > ...
</ldap:search>

<ldap:search [ host="hostname " port="port " ]
            [ user="bindDN " passwd="password " ]
            base="baseDN " [ srchScope="base|one|sub" ]
            [ filter="filterString " attrs="attrList " ]
            [ maxEntries="number " controls="beanName " ]
            var="varName " [ scope="varScope " response="varName " ]/>


ATTRIBUTES



host="hostname "  

Specify the hostname of the directory server. When this attribute is omitted, the default is localhost.  

port="port "  

Specify the port number of the directory server on the given host. When this attribute is omitted, the default port is 389.  

user="bindDN "  

Specify a bind DN for accessing your directory. If the bind DN and its password are omitted, the operation will use anonymous binding. The bind DN determines what entries and attributes will appear in the search results, according to the DN's access permissions.  

passwd="password "  

Specify the password for the bind DN. CAUTION: the password is visible in this tag, so the JSP file should be read-protected.  

base="baseDN "  

Specify the base DN for the search operation.  

srchScope="scope "  

Specify the scope of a search with one of the following values:
base - For searching only the base entry. This is the default.
one  - For searching only the children of the base entry.
sub  - For searching the base entry and all its descendants.
 

filter="filterString "  

Specify an LDAP filter string for the search. When omitted, the default filter is (objectclass=*), which returns all entries in the search scope.  

attrs="attrList "  

Specify the list of attributes that will be returned with their values for each entry in the search results. Attribute names in the list are separated by vertical bars (|).  

maxEntries="number "  

Specify the maximum number of entries to return. A search that yields more than this limit will generate an exception.

Regardless of the value specified here, if at all, a search will never return more entries than the number allowed by the directory server's nsslapd-sizelimit attribute whose default is 2,000 entries. See "nsslapd-sizelimit (Size Limit)" in the iPlanet Directory Server Command, Configuration and File Reference.  

entry="iterName "  

Give the name of the loop variable used to store each entry in turn when iterating through the search results. When this attribute is omitted, the default name of the loop variable is entry.  

var="varName "  

Give the name of the variable where the search results will be stored. This variable name and scope may be omitted when search results are processed in the element contents.  

scope="varScope "  

Give the scope of the variable where the search results will be stored. When omitted, the default scope is PAGE.  

controls="beanName "  

Give the name of a variable containing the LDAP controls for this search. See <ldap:sortControl> and <ldap:vlControl>.  

response="varName "  

Give the name of a variable (in the PAGE scope) for storing any error response. When omitted, the default name is response.
If an LDAP error occurs during the operation, this variable will be set to the corresponding LDAPException Bean.
 



DESCRIPTION
The <ldap:search> element searches the directory according to the specified base, search scope, and filter. There are two ways to process the search results:

  • Use other elements inside this tag to process each entry. The tag is an iterator and will evaluate its contents for each of the entries in the results.

  • Specify a variable name and optional scope for storing the search results. Then access this variable from other elements to process the entries it contains.

In both cases, the results may be accessed as variables or using the <ldap:dn> and <ldap:attr> tags to extract information.


EXAMPLES
This first example shows a simple search that displays the DN and several attributes for each result. The comments in the code explain the different ways to access attribute information in the results.

<ldap:search host="phonebook.siroe.com"
            user="cn=Directory Manager" passwd="password "
            base="ou=People,dc=siroe,dc=com" srchScope="sub"
            filter="(surname=a*)"
            attrs="dn|cn|employeeNumber|mail|telephonenumber">

   <!-- "entry" is the default iterator variable for results -->
   Entry: <jx:expr value="$entry"/><br>

   <!-- The DN can be read from the entry structure -->
   DN: <jx:expr value="$entry.dn"/><br>

   <!-- The pageContext Bean contains all attribute values -->
   cn: <%= ((EntryBean) pageContext.
            getAttribute("entry")).getAttr("cn").getValue() %><br>

   <!-- ldap:attr will display the value of the attribute -->
   ID: <ldap:attr entry="$entry" name="employeeNumber"/><br>

   <!-- ldap:attr can also store the value of the attribute, for
        use in other expressions -->
   <ldap:attr entry="$entry" name="mail" var="address" default=""/>
   mail: <jx:if test="$address != ''">
            <A HREF=mailto:<jx:expr value="$address"/>
            ><jx:expr value="$address"/></A>
         </jx:if><br>

   <!-- For multivalued attributes, use ldap:attr to retrieve all
        values, then iterate -->
   <ldap:attr entry="$entry" name="telephonenumber" op="values"
             var="values" scope="sess"/>
   <jx:forEach var="val" items="$session:values">
      telephonenumber: <jx:expr value="$val"/>
   </jx:forEach><p>

</ldap:search>

The next example performs an anonymous search and retrieves all attributes of the matching entries. It uses iterators inside the <ldap:search> element to display them all in the search results.

<ldap:search host="phonebook.siroe.com"
            base="ou=People,dc=siroe,dc=com" srchScope="sub"
            filter="(surname=b*)" var="results">

   Entry: <jx:expr value="$entry"/><br>
   DN: <jx:expr value="$entry.dn"/><br>
   Number of attributes:
      <jx:expr value="$entry.size" default="NULL"/><P>

   <table border="0" cellpadding="0" cellspacing="2">
      <jx:forEach var="oneAttr" items=$entry><tr>

         <td valign="top" align="right" nowrap>
            <jx:expr value="$oneAttr.name">
         </td>

         <td valign="top">
            <jx:forEach var="oneVal" items="$oneAttr">
               <jx:expr value="$oneVal"><br>
            </jx:forEach>
         </td>

      </tr></jx:forEach>
   </table>
</ldap:search>

<P>Number of entries returned:
   <jx:expr value="$results.size" default="NULL"/><br><br>

The following example stores search results in a variable and accesses them outside of the <ldap:search> element. It also shows all information that is available for each attribute retrieved in a search. The search itself returns all configuration attributes under the configuration root entry.

<ldap:search host="phonebook.siroe.com"
            user="cn=Directory Manager" passwd="password "
            base="o=NetscapeRoot" srchScope="one"
            var="result"/>

<util:logScopes/>

<jx:forEach var="entry" items="$result">
   <!-- Search scope one should return only a single entry -->
   Entry: <jx:expr value="$entry"/><br>
   DN: <jx:expr value="$entry.dn""/><br>

   <jx:forEach var="oneAttr" items="$entry">
      Name=<jx:expr value="$oneAttr.name"/><br>
      <jx:forEach var="oneVal" items="$oneAttr">
         Value=<jx:expr value="$oneVal"/><br>
      </jx:forEach>
      Single.Value=<jx:expr value="$attr.value"
                          default="NULL"/><br>
      Size=<jx:expr value="$attr.size"/><br>
      Subtype=<jx:expr value="$attr.subtype" default="NULL"/><br>
      Values=<jx:expr value="$attr.values" default="NULL"/><br>
      ByteValue=<jx:expr value="$attr.byteValue"
                       default="NULL"/><br>
      ByteValues=<jx:expr value="$attr.byteValues"
                        default="NULL"/><br>

</jx:forEach>

</ldap:search>

The last example produces an exception by setting a low limit to the number of entries returned and then displays all information about the exception.

<ldap:search host="phonebook.siroe.com"
            base="ou=People,dc=siroe,dc=com" srchScope="sub"
            maxEntries="3" response="searchError">
   DN=<jx:expr value="$entry.dn" default="NULL"/>
</ldap:search>

Response:
   <jx:expr value="$searchError" default="NULL"/><br>
Response.code:
   <jx:expr value="$searchError.code" default="NULL"/><br>
Response.exception:
   <jx:expr value="$searchError.exception" default="NULL"/><br>
Response.message:
   <jx:expr value="$searchError.message" default="NULL"/><br>
Response.klass:
   <jx:expr value="$searchError.klass" default="NULL"/><br>


SEE ALSO
<ldap:attr>, <ldap:dn>,
<ldap:sortControl>, <ldap:vlControl>, <ldap:vlControl>



<ldap:attr>

Defines an attribute-value pair for the <ldap:add> element or retrieves an attribute-value pair from an <ldap:search> result.


SYNTAX
For defining an attribute:

<ldap:attr name="attrName " value="valueString "
          [ var="varName " scope="scopeName " ]/>

For displaying an attribute:

<ldap:attr name="attrName " entry="varName "
          [ default="valueString " op="value|values" ]
          [ var="varName " scope="scopeName " ]/>


ATTRIBUTES



name="attrName "  

Give the name of the LDAP attribute to define or retrieve.  

value="valueString "  

Specify the value when defining an attribute to add.  

var="varName "  

Give the name of the variable where this attribute definition will be stored. The variable name and scope are not required when the <ldap:attr> tag is contained in the <ldap:add> element.

The variable name and scope may also be used to store the retrieved value for later access, such as for iterating through a multi-valued attribute.  

scope="varScope "  

Give the scope of the variable where this attribute definition or values will be stored.  

entry="varName "  

Specify the name of variable that contains an entry of the search results.  

default="valueString "  

Specify a default value to store or display when the attribute is missing or when its value is null or empty.  

op="operation "  

Specify the extent of the value to retrieve:
value  - Retrieve a single value or the first of a multi-valued
        attribute; this is the default behavior.
values - Retrieve all attribute values as an array.
 



DESCRIPTION
The <ldap:attr> element represents an LDAP attribute, its name and its values. It is used with the <ldap:add> element to define the attributes of a new entry. It also simplifies the access to attributes and their values in search results.

This element may appear inside the <ldap:add> element where it defines the name and value of a new attribute. It may also be referenced from outside the <ldap:add> element, in which case this element must also name a variable and optional scope where the definition is stored. See "<ldap:search>" for more information.

When processing search results, the <ldap:attr> element extracts the value or values of the named attribute for display or storage in a variable. Use the entry attribute to name the variable containing search results, either inside or outside of an <ldap:search> element.


SEE ALSO
<ldap:add> and its examples, <ldap:search> and its examples.



<ldap:dn>

Normalize or extract distinguished name (DN) components for display or storage.


SYNTAX
<ldap:dn value="DNstring " [ op="leaf|leaf-value|parts|value-parts" ]
        [ var="varName " scope="scopeName " ]/>

<ldap:dn [ op="leaf|leaf-value|parts|value-parts" ]
        [ var="varName" scope="scopeName" ]>
   DNstring
</ldap:dn>


ATTRIBUTES



value="DNstring "  

Specify the DN on which to operate. This attribute is optional because the DN may also be specified as the element's contents.  

op="operation "  

Specify the DN component or components to extract from the DN:
leaf        - Extracts the DN's first naming attribute and value.
leaf-value  - Extracts only the first naming value from the DN.
parts       - Returns an array of each of the DN's components.
value-parts - Returns an array containing only the DN's values.
 

var="varName "  

Give the name of the variable where the tag's output will be stored.  

scope="varScope "  

Give the scope of the variable where the tag's output will be stored.  



DESCRIPTION
This element extracts the comma-separated components of a distinguished name (DN), according to the op attribute. If no operation is specified, the element will normalize the DN string. The DN is specified either as the value attribute or as the tag's contents.

Specify a variable name and optional scope to store the component string or array of strings in a variable. If none is specified, the element will display component in the output.


EXAMPLES
INPUT DN STRING: 'CN=Babs Jensen,OU=People,dc=siroe,dc=com'

Normalize =
   <ldap:dn>CN=Babs Jensen,OU=People,dc=siroe,dc=com</ldap:dn><br>

Leaf Value =
   <ldap:dn value="CN=Babs Jensen,OU=People,dc=siroe,dc=com"
           op="leaf-value"/><br>

Leaf =
   <ldap:dn value="CN=Babs Jensen,OU=People,dc=siroe,dc=com"
           op="leaf"/><br>

<ldap:dn value="CN=Babs Jensen,OU=People,dc=siroe,dc=com"
        op="value-parts" var="values"/>
<jx:forEach var="val" items="$valuess">
   Value Part: <jx:expr value="$val"/><br>
</jx:forEach>

<ldap:dn value="CN=Babs Jensen,OU=People,dc=siroe,dc=com"
        op="parts" var="parts"/>
<jx:forEach var="part" items="$parts">
   Part: <jx:expr value="$part"/><br>
</jx:forEach>



<ldap:sortControl>

Define an LDAPSortControl for sorting search results. This element must contain <ldap:sortKey> elements to specify the keys.


SYNTAX
<ldap:sortControl var="varName " [ scope="scopeName " ]>
   <ldap:sortKey ... > ...
</ldap:sortControl>


ATTRIBUTES



var="varName "  

Give the name of the variable where the sort control will be stored.  

scope="varScope "  

Give the scope of the variable where the sort control will be stored.  



DESCRIPTION
Use the <ldap:sortControl> and <ldap:sortKey> elements together to specify one or more attributes to use for sorting search results. The first <ldap:sortKey> element it contains will be the primary sort key, the second one will be the secondary sort key, and so on.

Specify a variable name and optional scope to store the control definition and then reference this variable with the controls attribute of the <ldap:search> element. You may add the sort controls to an existing variable, as long as it is an instance of a ControlsBean, created by either <ldap:sortControl> or <ldap:vlControl>.


EXAMPLES
<ldap:sortControl var="controls">
   <ldap:sortKey key="sn"/>
   <ldap:sortKey key="givenname"/>
</ldap:sortControl>

<ldap:search host="phonebook.siroe.com"
            base="ou=People,dc=siroe,dc=com" srchScope="sub"
            filter="(surname=a*)" controls="$controls"
            attrs="dn|sn|givenname|employeeNumber|telephonenumber"
            var="results" scope="page" response="searchError"/>


SEE ALSO
<ldap:vlControl>, <ldap:search>



<ldap:sortKey>

Defines the attribute to use for sorting within an <ldap:sortControl> element.


SYNTAX
<ldap:sortKey key="attrName " [ reverse="yes" matchRule="OID " ]/>


ATTRIBUTES



key="attrName "  

Specify the name of the attribute to use as the sort key.  

reverse="yes"  

Specify reverse sort order on the given key. When omitted, forward sort order is used by default.  

matchRule="OID "  

Specify the OID of a matching rule applicable to the attribute key.  



DESCRIPTION
The <ldap:sortKey> element may only occurs within an <ldap:sortControl> element. It specifies an attribute to use as the key for sorting the results of a search, and optionally reverse sort order or a matching rule.


SEE ALSO
<ldap:sortControl> and its examples.



<ldap:vlControl>

This element may be used in conjunction with <ldap:sortControl> to perform searches with sorted virtual lists (VL).


SYNTAX
For the initial search:

<ldap:vlControl jump="string " before="number " after="number "
               var="varName " [ scope="scopeName " ]/>

For subsequent searches in the same virtual list:

<ldap:vlControl start="index " before="number " after="number "
               content="number " var="varName " [ scope="scopeName " ]/>


ATTRIBUTES



jump="string "  

Specify a string value or partial value for the first VL search. This string will be matched against the value of the sort key attribute to determine the initial index of the virtual list.  

start="index "  

Specify the index of the target entry in the virtual list during subsequent searches.  

before  

Specify the number of entries preceding the indexed entry to return in the VL search results.  

after  

Specify the number of entries following the indexed entry to return in the VL search results.  

content  

The number of entries in the complete search results. This number is returned during the first search and should be sent with subsequent searches of the same virtual list.  

var="varName "  

Give the name of the variable where the VL control will be stored.  

scope="varScope "  

Give the scope of the variable where the VL control will be stored.  



DESCRIPTION
The <ldap:vlControl> element allows you to add virtual list (VL) functionality to sorted searches. Use in conjunction with the <ldap:sortControl> by specifying the same name and optional scope for the var and scope attributes.


EXAMPLES
<ldap:sortControl var="controls">
   <ldap:sortKey key="cn"/>
</ldap:sortControl>

<ldap:vlControl jump="A" before="5" after="5" var="controls"/>

<ldap:search host="phonebook.siroe.com"
            base="ou=People,dc=siroe,dc=com" srchScope="sub"
            filter="(surname=a*)" controls="$controls"
            var="results" scope="page" response="searchError"/>

VL Response = <jx:expr value="$results.vlResponse" default="NULL"/>

<table border="2">
   <jx:forEach var="entry" items="$results">
      <tr><td><ldap:attr entry="$entry" name="cn"/></td></tr>
   </jx:forEach>
</table>

<!-- Use the VL info from the first search to prepare subsequent
     searches of the same list. -->
<jx:set var="first" value="$results.vlResponse.firstPosition"/>
<jx:set var="count" value="$results.vlResponse.contentCount"/>

<% Integer firstI = (Integer) pageContext.getAttribute("first");
   Integer countI = (Integer) pageContext.getAttribute("count");
   if ((firstI != null) && (countI != null)) {
      int next = firstI.intValue() + 10;
      if (next <= countI.intValue())
         application.setAttribute("next", new Integer(next));
      else
         application.removeAttribute("next");
   }
   application.removeAttribute("last");
%>


SEE ALSO
<ldap:sortControl>, <ldap:search>



Utilities Tag Library (util)



The Utilities Tag Library is built on JSPTL and provides some useful elements for writing LDAP-enabled JSP applications. These tags perform such tasks as reading values from a properties file, testing the existence of an attribute, and so on.



<util:importParams>

Import all parameters from the ServletRequest into the REQUEST scope.


SYNTAX
<util:importParams/>


DESCRIPTION
This element reads all the parameters of the request and sets page context attributes, either single or multivalued, in the REQUEST scope.



<util:present>

Checks the existence of a variable and returns true if present.


SYNTAX
<util:present name="varName " [ scope="nameScope " var="varName " ]/>


ATTRIBUTES



name="varName "  

Specify the name of the variable of which to test the existence.  

scope="nameScope "  

Specify the scope in which to find the variable to test. When omitted, the variable name is assumed to be in the PAGE scope.  

var="varName "  

Specify the name of the variable where the boolean result will be stored. When omitted, the variable will be called present.  



DESCRIPTION
This element checks for the existence of a variable name in a given scope and sets a boolean value in another variable. The result is true if the named variable exists and false otherwise.

The scope attribute of this tag determines the scope of the variable name to test, not the scope of the output variable.



<util:prop>

Retrieve a property value from a properties file.


SYNTAX
<util:prop prps="bundleName " key="propName " [ def="value " ]
          [ lang="subtype " cntry="subtype " varnt="localeVariant " ]
          [ var="varName " scope="varScope " ]/>


ATTRIBUTES



prps="bundleName "  

Specify the name of the properties bundle, which is the same as the properties file name without the .properties suffix.  

key="propName "  

Specify the name of the key name of the value to be retrieved.  

def="value "  

Give a default value that will be returned if the key is not defined in the properties bundle.  

lang="subtype "
cntry="subtype "
varnt="localeVariant "
 

Specify the language and country subtypes that define a locale. You must specify a language and country together, and you may also give an optional locale variant.
These three attributes determine which properties file to access. When omitted, the properties for the default locale are used.
 

var="varName "  

Give the name of the variable where the property value will be stored.  

scope="varScope "  

Give the scope of the variable where the property value will be stored. When omitted, the default scope is PAGE.  



DESCRIPTION
This element will retrieve value corresponding to the given property key from a properties file. You may specify the language, country, and variant that determine a locale through the lang, cntry, and optional varnt attributes.

The name of the properties bundle and optional locale determine the name of the file where the keys and values are defined. The element will return an error if the file cannot be found.

The property key is the name of the property, as found in the file. You may also specify an optional default value that will be returned when the key does not exist in the file.

If you do not specify a variable and optional scope in which to store the property value, it will be displayed as part of the page output.


EXAMPLES
The following example from the LookMeUp application uses localized properties to create a row of headings in a table output.

<table border="0" cellpadding="1" cellspacing="0" width="100%"
      bgcolor="#FFFFFF" align="center">
   <tr align="left" bgcolor="#990000"> <!-- Shaded heading row -->

      <td><b>
         <util:prop prps="screen" key="searchresults.name"
                   lang="$app:language" cntry="$app:country"/>
      </b></td>

      <td><b>
         <util:prop prps="screen" key="searchresults.phone"
                   lang="$app:language" cntry="$app:country"/>
      </b></td>

      <td><b>
         <util:prop prps="screen" key="searchresults.email"
                   lang="$app:language" cntry="$app:country"/>
      </b></td>

   </tr> ...
</table>



<util:encode>

Encode a string into UTF-8 format.


SYNTAX
<util:encode [ var="varName " scope="varScope " ]>inputString </util:encode>

<util:encode value="inputString " [ var="varName " scope="varScope " ]/>


ATTRIBUTES



value="inputString "  

Specify the value to be encoded.  

var="varName "  

Give the name of the variable where the encoded value will be stored.  

scope="varScope "  

Give the scope of the variable where the encoded value will be stored. When omitted, the default scope is PAGE.  



DESCRIPTION
This element converts its contents or its value attribute to UTF-8, where all characters are encoded on 8 bits.

If you do not specify a variable and optional scope in which to store the encoded value, it will be displayed as part of the page output.


EXAMPLES
DN string: "cn=Babs Jensen,ou=People,dc=siroe,dc=com"
Normalized:
   <ldap:dn value="cn=Babs Jensen,ou=People,dc=siroe,dc=com"/>
<ldap:dn value="cn=Babs Jensen,ou=People,dc=siroe,dc=com" var="dn"/>
Encoded: <util:encode value="$dn"/>



<util:date>

Outputs a date and time string using the java.text.DateFormat class.


SYNTAX
<util:date [ value="timeString " format="SHORT|MEDIUM|LONG|FULL" ]
          [ lang="subtype " cntry="subtype " varnt="localeVariant " ]
          [ var="varName " scope="varScope " ]/>>


ATTRIBUTES



value  

Give a date and time string to be reformatted. This input must be an ISO 2014 timestamp (YYYYMMDDHHmmss Z) or in a format recognized by the java.text.DateFormat.parse method. When this attribute is omitted, the tag will output the current date.  

format  

Specify the format of the output date and time string. The possible values are the same as the date format constant fields defined in java.text.DateFormat. The format is locale dependent, but generally, the formats have the following characteristics:
SHORT  - Completely numeric, for example 02/02/02 or 12:34pm.
MEDIUM - Uses abbreviations: Feb 02, 2002; this is the default.
LONG   - Spells out the date and includes times with seconds.
FULL   - Includes day of the week and time zone.
 

lang="subtype "
cntry="subtype "
varnt="localeVariant "
 

Specify the language and country subtypes that define a locale. You must specify a language and country together, and you may also give an optional locale variant.
These three attributes determine the locale for the date format. When omitted, the default locale is used.
 

var="varName "  

Give the name of the variable where the date string will be stored.  

scope="varScope "  

Give the scope of the variable where the date string will be stored. When omitted, the default scope is PAGE.  



DESCRIPTION
The <util:date> element generates a date and time string according to the given locale. For a complete description of the possible date formats, see the API reference for the java.text.DateFormat class.

By default the element will display the current date in the page output. However, you may specify a different date string to reformat, and you may give the name of a variable and optional scope to store the formatted string.


EXAMPLES
SHORT: <util:date format="short"/>
MEDIUM: <util:date format="medium"/>
LONG: <util:date format="long"/>
FULL: <util:date format="full"/><P>
DEFAULT: <util:date/><P>
TIMESTAMP 20010807163841Z:
   <util:date format="full" value="20010807163841Z"/>



<util:log>

Writes a string to the log file.


SYNTAX
<util:log value="logString "/>


ATTRIBUTES



value="logString "  

Give the string value to be written in the log.  



DESCRIPTION
This element will add the following line to the ServletContext log:

<Log> logString


EXAMPLES
<util:log value="Log this value"/>



<util:logScopes>

Logs all variables and values defined currently defined in all scopes.


SYNTAX
<util:logScopes/>


DESCRIPTION
This element will write a section in the ServletContext log containing the name and value of all variables or attributes in the following scopes:


SEE ALSO
<util:log>



JSP Standard Tag Library (jsptl)



JSPTL is the Early Access release of the standard JavaServer Pages Tag Library. It contains simple tags that provide core functionality common to many JSP applications.

While the JSPTL has been superseded by the JSP Standard Tag Library (JSTL), the LookMeUp application relies on the older JSPTL described in this section.

JSPTL EA1 is comprised of two tag libraries. The two libraries contain very common sets of tags, with one major difference: the first library (jr) has tags that accept rtexprvalues for their attributes, while the second library (jx) accepts attribute values specified using the expression languages (EL) introduced in JSPTL.

Include the following line at the top of your .jsp file to use the jr library:

<%@ taglib uti=http://java.sun/com/jsptl/ea/jr prefix="jr" %>

You may choose any prefix, but jr is the current recommendation for the rtexprvalue version of the JSPTL library.

The LookMeUp application relies on the jx library that supports expression languages. The application files use the following directive:

<%@ taglib uti=http://java.sun/com/jsptl/ea/jx prefix="jx" %>



<jx:expr>

Returns the value of its expression.


SYNTAX
<jx:expr value="valueExpr " [ default="value " ]/>


ATTRIBUTES



value="valueExpr "  

Specify an expression that will be the value to return. Use the $varName syntax to retrieve the value of a variable.  

default="value "  

Give a default value to be returned if the variable does not exist or has a null value.  



DESCRIPTION
Use this tag to fetch the value of a variable by specifying the $varName syntax in the value attribute.

This element is the EL-equivalent of the <%=... %> element.


SEE ALSO
<jx:set> and its example.



<jx:set>

Store the result of an expression evaluation in a scoped variable.


SYNTAX
<jx:set var="varName " [ scope="varScope " ] value="valueExpr "/>

<jx:set var="varName " [ scope="varScope " ]>contents </jx:set>


ATTRIBUTES



value="valueExpr "  

Specify an expression that will be the value to store. Use the $varName syntax to specify the value of a variable.  

var="varName "  

Give the name of the variable where the value will be stored.  

scope="varScope "  

Give the scope of the variable where the value will be stored. When omitted, the default scope is PAGE.  



DESCRIPTION
Use this tag to evaluate an expression in the value attribute and store its result in the designated variable and optional scope. You may also store the elements which are contents of this tag in the designated variable.


EXAMPLE
<jx:set var="city" value="$custmer.address.city"/>
<jx:set var="customerFmt" scope="request">
   <font color="red">
      <jx:expr value="$city"/>
   </font>
</jx:set>



<jx:declare>

Declares a scripting variable.


SYNTAX
<jx:declare id="varName " [ type="typeClass " ]/>


ATTRIBUTES



id="varName "  

Specify the name of the scripting variable.  

type="typeClass "  

Specify the type or Java class of the attribute. When omitted, the default type is java.lang.Object.  



DESCRIPTION
Declares a scripting variable, initially defined by an existing scoped attribute of the same name.


EXAMPLE
<jx:declare id = "customer" type= "acme.Cutomer" />



<jx:forEach>

The basic iteration tag, accepting many different collection types.


SYNTAX
<jx:forEach var="iterName " items="varName " [ status="varName " ]
           [ begin="index " end="index " step="number " ]>
   contents
</jx:forEach>


ATTRIBUTES



var="iterName "  

Specify the name of the variable in which to store the current iteration value.  

items="varName "  

Give the name of a variable containing values on which to iterate. With each iteration, the variable named by the var attribute will take the value of one of these items.  

status="varName "  

Specify the name of a variable from which loop status information, such as the current index, may be read.  

begin="index "  

Specify the index of the first element to process. The index value must be greater than or equal to 0. When omitted, iteration will start with the first element of the items variable.  

end="index "  

Specify the index of the last element to process. The index value must be greater than or equal to the begin index. When omitted, iteration will end with the last element of the items variable.  

step="number "  

Specify the number steps to advance in the list of items with each iteration. The step number must be greater than or equal to 1. The default step is 1. For example, step="2" will process every other element in the items variable.  



DESCRIPTION
This element will process its contents once for every iteration defined by the items attribute and by the optional begin, end, and step attributes. During the iteration, the variable named by the var attribute will contain each value of the items in sequence. For example, this element allows you to process each value of a multi-valued LDAP attribute.


EXAMPLE
<jx:forEach var="customer" items="$customers">
   <jx:expr value="$customer.name">
</jx:forEach>



<jx:forToken>

Iterates over tokens in a string, separated by the specified delimiters.


SYNTAX
<jx:forToken var="iterName " items="tokenString " delims="delimChars "
            [status="varName " begin="index " end="index " step="number "]>
   contents
</jx:forToken>


ATTRIBUTES



var="iterName "  

Specify the name of the variable in which to store the current iteration value.  

items="tokenString "  

Give a string containing the tokens on which to iterate. With each iteration, the variable named by the var attribute will take the value of each token.  

delims="delimChars "  

The set of characters that delimit the tokens in the tokenString. Each character in this string is a separator.  

status="varName "  

Specify the name of a variable from which loop status information, such as the current index, may be read.  

begin="index "  

Specify the index of the first token to process. The index value must be greater than or equal to 0. When omitted, iteration will start with the first token of the items variable.  

end="index "  

Specify the index of the last token to process. The index value must be greater than or equal to the begin index. When omitted, iteration will end with the last token of the items variable.  

step="number "  

Specify the number steps to advance in the list of items with each iteration. The step number must be greater than or equal to 1. The default step is 1. For example, step="2" will process every other token in the items variable.  



DESCRIPTION
This element will process its contents once for every token defined by the items and delims attributes. As with the <jx:forEach> element, you may modify the iteration sequence with the optional begin, end, and step attributes. During the iteration, the variable named by the var attribute will contain each token in sequence. For example, this element allows you to process strings containing fields or choice values.


EXAMPLE
<jx:forToken var="token" items="blue|white|red" delims="|">
   contents
</jx:forToken>



<jx:if>

The basic conditional tag.


SYNTAX
<jx:if test="boolExpr " [ var="varName " scope="varScope " ]>
   contents
</jx:if>


ATTRIBUTES



test="boolExpr "  

Specify a boolean expression that will evaluate to true or false.  

var="varName "  

Give the name of the variable where the boolean test result will be stored.  

scope="varScope "  

Give the scope of the variable where the boolean will be stored. When omitted, the default scope is PAGE.  



DESCRIPTION
The <jx:if> element evaluates its contents if the boolean expression in the test attribute evaluates to true. The optional var attribute names a variable to store the Boolean result of evaluating the test condition.


EXAMPLES
<jx:if test="$customer.address.country == 'USA'"
       var="isUsCustomer">
   contents
</jx:if>


SEE ALSO
<jx:choose> <jx:when> <jx:otherwise>



<jx:choose> <jx:when> <jx:otherwise>

Conditional tag that allows mutually exclusive conditional operations marked by <jx:when> and <jx:otherwise>.


SYNTAX
<jx:choose>
   <jx:when test="boolExpr ">
      contents
   </jx:when>
   ...
   [ <jx:otherwise>
      contents
   </jx:otherwise> ]
</jx:choose>


ATTRIBUTES



test="boolExpr "  

Specify a boolean expression that will evaluate to true or false.  



DESCRIPTION
The <jx:choose>, <jx:when>, and <jx:otherwise> elements allow the common if-then-elsif-else conditional construct.

The <jx:choose> element must directly contain one or more <jx:when> elements. It may directly contain an optional <jx:otherwise> element which must occur last. The boolean expressions in the test attributes will be evaluated in the order they appear and the contents of the first one that is true will be evaluated. If all are false, the contents of the <jx:otherwise> element will be evaluated, if present.


EXAMPLE
<ldap:search host="phonebook.siroe.com"
            base="ou=People,dc=siroe,dc=com" srchScope="sub"
            var="results" response="searchError"/>

<jx:choose>
   <jx:when test="$searchError == 'NULL'">
      <!-- process the search results -->
      <jx:choose>
         <jx:when test="$results.size > 1">
            <!-- display a table of search results-->
            <%@ include file="searchresults.jsp" %>
         </jx:when>

         <jx:when test="$results.size == 1">
            <!-- extract the single result from the list -->
            <jx:forEach var="result" items="$results">
               <!-- set the request:dn for use in person.jsp -->
               <jx:set var="dn" scope="request"
                      value="$result.dn"/>
               <jsp:include page="person.jsp"></jsp:include>
            </jx:forEach>
         </jx:when>
         <jx:otherwise>
            <!-- Display a message -->
            <h1><center>No matching entry was found</h1>
         </jx:otherwise>
      </jx:choose>
   </jx:when>

   <jx:otherwise>
      <!-- display the search error -->
      Response: <jx:expr value="$resp" default="NULL"/><br>
      Message:
         <jx:expr value="$resp.message" default="NULL"/><br>
   </jx:otherwise>
</jx:choose>

Previous     Contents     Index     Next     
Copyright 2002 Sun Microsystems, Inc.. All rights reserved.

Last Updated April 15, 2002