I think you need commons-collections.jar.

[EMAIL PROTECTED] wrote:

>Hi, I looked at Ted Husted's example (Ted's catalogue) for using
>BeanUtils.populate() to populate beans from a database query, and put them
>into an ArrayList.
>I am working on some code which queries an LDAP Directory and requires the
>same kind of functionality. I reworked Ted's example to fit my needs, but
>the beans never seem to get populated, so I end up with a ArrayList of empty
>beans! I am using the package org.apache.commons.beanutils to do this and I
>have tried version 1.0 and 1.1.
>The relevant part of the code is shown below. I may have missed something
>obvious, but I cannot see it! I have already verified that I am getting data
>from the LDAP query, and I am believe the problem lies in popuating the
>bean.
>
>Thanks in advance
>
>Neil
>
>*****************************************************************
>
>
>     // start looping over the LDAP entries...
>      while ( searchResults.hasMoreElements())
>      {
>        LDAPEntry nextEntry = null;
>        try
>        {
>          nextEntry = searchResults.next();
>        }
>        catch(LDAPException e)
>        {
>          System.out.println("Error: " + e.toString());
>
>          // Exception is thrown, go for next entry
>          continue;
>        }
>
>        // create a HashMap to hold att/val pairs...
>        HashMap properties = new HashMap();
>
>        LDAPAttributeSet attributeSet = nextEntry.getAttributeSet();
>        Enumeration allAttributes = attributeSet.getAttributes();
>
>        // loop over each attribute..
>        while(allAttributes.hasMoreElements())
>        {
>          LDAPAttribute attrib = (LDAPAttribute)allAttributes.nextElement();
>
>          // get the current attribute name...
>          String attributeName = attrib.getName();
>
>          // get the value(s) for this attribute...
>          String[] Values = attrib.getStringValueArray();
>
>
>          // if we have at least 1 value for this attribute...
>          if( allValues.length != 0)
>          {
>            properties.put(attributeName, Values);
>          }
>        }
>
>        // now populate bean for this entry...
>        try
>        {
>          //instantiate new bean to hold results...
>          UserResult userresult = new UserResult();
>
>          BeanUtils.populate(userresult,properties);
>          list.add(userresult);
>
>        }
>        catch (Exception e)
>        {
>          throw new IllegalAccessException("RequestUtils.getCollection: " +
>e.toString());
>        }
>      }
>
>*******rest of code follows.......
>
>
>
>--
>To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
>For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
>
>
>




--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to