Announcement Announcement Module
Collapse
No announcement yet.
How to delete an attribute ? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to delete an attribute ?

    Hi,

    Using the LdapTemplate class you have the handy method modifyAttributes(). Do you know how you delete an attribute using the template ?

    Thanks in advance,
    Juan

  • #2
    Have you tried setting the mod operation to REMOVE_ATTRIBUTE on the modificationItem.
    http://java.sun.com/j2se/1.4.2/docs/...LACE_ATTRIBUTE

    Comment


    • #3
      The basic way of doing it is to use the REMOVE_ATTRIBUTE, as Karl describes, but working with ModificationItems is kind of tricky business so we provide a helper class to manage this kind of thing: DirContextAdapter. It's all described in the reference documentation, but what you would do is something like this:
      Code:
      DirContextAdapter ctx = (DirContextAdapter) ldapTemplate.lookup(entryDn);
      // Set some attribute values
      ctx.setAttributeValue("someAttribute", "newValue");
      ctx.setAttributeValues("someOtherAttribute", new String[]{"value1", "value2"});
      //... set more new attribute values
      ldapTemplate.modifyAttributes(entryDn, ctx.getModificationItems());
      The getModificationItems() method will automagically construct the necessary ModificationItems reflecting the changes you made.

      Comment

      Working...
      X