Hi, Frank. I created a similar method, but rather a static one than a member method. So mine is in a class called BeanUtil (not the apache commons beanutils) and applicable to any other java bean. No need to modify the base class or whatever. So I can apply it on FormBeans as well as servletRequests or whatever may come, which suits me more for debugging.
Hiran ----------------------------------------- Hiran Chaudhuri SAG Systemhaus GmbH Elsenheimer Straße 11 80867 München Phone +49-89-54 74 21 34 Fax +49-89-54 74 21 99 > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > Sent: Mittwoch, 6. Oktober 2004 18:18 > To: [EMAIL PROTECTED] > Subject: Proposed Action base class change > > Hello all... > > I find myself all the time overloading toString() of my > ActionForms for debugging purposes, so I can easily dump the > current state of the object. I had been doing this for each > ActionForm class, specifically for it, but it ocurrs to me > that a general-purpose reflection-based approach would be better. > > I'd like to propose adding this functionality to the > ActionForm base class. Here's the code I propose adding: > > import java.lang.reflect.Field; > public static final AVERAGE_FIELD_SIZE = 25; public String > toString() { > String str = ""; > StringBuffer sb = null; > try { > Field[] fields = this.getClass().getDeclaredFields(); > sb = new StringBuffer(fields.length * AVERAGE_FIELD_SIZE); > for (int i = 0; i < fields.length; i++) { > if (sb.length() > 0) { sb.append(", "); } > sb.append(fields[i].getName() + "=" + fields[i].get(this)); > } > str = sb.toString().trim(); > } catch (Exception e) { > str = "Exception in ActionForm.toString() : " + e; > } > return str; > } > > The value of AVERAGE_FIELD_SIZE is a matter of debate, and > it's of course impossible to come up with a real value, so > something reasonable is the answer. 25 struck me as a decent > starting point. > > What does everyone think? I find this functionality to be > very useful in my work, and I suspect others may as well. > The code doesn't add any dependencies outside J2SE, and it's > certainly simple enough as to not be particularly risky. > > Thanks all! > > Frank W. Zammetti > Founder and Chief Software Architect > Omnytex Technologies > http://www.omnytex.com > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]