Results 1 to 3 of 3

Thread: How to return a list of multi-value attributes

  1. #1
    Join Date
    Nov 2009
    Posts
    10

    Default How to return a list of multi-value attributes

    1. How can I return a list of all values of a multi-value attribute?
    I'm using the snippet below and have tried changing return ctx.getStringAttribute("aaaReply"); to return ctx.getStringAttributes("aaaReply"); with no effect.
    Is there something I'm missing?


    List<String> list = (List<String>)ldapTemplate.search(dn,
    "(&(objectClass=users)(uid=test)(aaaReply=Fram ed-IP-Address=*))",
    new AbstractContextMapper() {
    protected Object doMapFromContext(DirContextOperations ctx) {
    return ctx.getStringAttribute("aaaReply");
    }
    });

    -------------------------------------------

    Thanks,
    Dave

  2. #2

    Default

    Do you have more than one value in the aaaReply attribute in the object that matches the filter you specified?

    The ctx.getStringAttributes("aaaReply") call should return an array containing all the attribute values.

  3. #3
    Join Date
    Jul 2005
    Location
    Helsingborg, Sweden
    Posts
    504

    Default

    If you return multiple values from your mapper, you should specify that in your List. Below I do so by choosing to return a String array from the mapper:

    Code:
    List<String[]> list = (List<String[]>) ldapTemplate.search(dn, 
       "(&(objectClass=users)(uid=test)(aaaReply=Fram ed-IP-Address=*))",
       new AbstractContextMapper() {
          protected Object doMapFromContext(DirContextOperations ctx) {
             return ctx.getStringAttributes("aaaReply");
          }
       });
    The same code, only using the type-safe SimpleLdapTemplate:

    Code:
    List<String[]> list = simpleLdapTemplate.search(dn, 
       "(&(objectClass=users)(uid=test)(aaaReply=Fram ed-IP-Address=*))",
       new ParameterizedContextMapper<String[]>() {
          public String[] mapFromContext(Object ctx) {
             DirContextOperations adapter = (DirContextOperations) ctx;
             return adapter.getStringAttributes("aaaReply");
          }
       });
    Ulrik Sandberg
    Jayway (www.jayway.com)
    Spring LDAP project member

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •