Announcement Announcement Module
Collapse
No announcement yet.
How to return a list of multi-value attributes Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

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

    Comment


    • #3
      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");
            }
         });

      Comment

      Working...
      X