[Webwork-user] usefull copyBeanToMap method for webwork
Brought to you by:
baldree,
rickardoberg
From: Francisco H. <lag...@ho...> - 2002-08-07 04:38:12
|
I was looking for a method to copy a Bean to a Map, I was able to find lots of methods that copied Maps to Beans.. not any for Bean to Map, anyways, heres my attempt at one.. anyone else think this method might be useful in webwork? public static void copyBeanToMap(Object from, Map to) throws IllegalArgumentException { try { Object[] writeParameters = new Object[1]; String val; PropertyDescriptor[] propertiesFrom = getPropertyDescriptors(from.getClass()); for (int j = 0; j < propertiesFrom.length; j++) { PropertyDescriptor pdFrom = propertiesFrom[j]; val = (String) pdFrom.getReadMethod().invoke(from, new Object[0]); to.put(pdFrom.getDisplayName(), val); } } catch (Exception e) { throw new IllegalArgumentException("Bean copy failed:" + e); } } _________________________________________________________________ Chat with friends online, try MSN Messenger: http://messenger.msn.com |