Re: Introspection used in Struts (Was: Bean convention vs. Struts convention)
At 09:38 PM 8/7/2001 -0700, you wrote: Struts already does it (inside the PropertyUtils class). The first time it encounters a particular bean class, Struts executes: BeanInfo beanInfo = Introspector.getBeanInfo(bean.getClass()); PropertyDescriptor descriptors[] = beanInfo.getPropertyDescriptors(); and caches the descriptors[] array. Each PropertyDescriptor already has a direct reference to the appropriate getter and setter Method objects, so they are in effect being cached as well. Struts!!! Struts!!! Struts!!! :-) Thanks, Craig. -- John Yu Scioworks Technologies e: [EMAIL PROTECTED] w: +(65) 873 5989 w: http://www.scioworks.com m: +(65) 9782 9610
Re: Introspection used in Struts (Was: Bean convention vs. Strutsconvention)
On Wed, 8 Aug 2001, John Yu wrote: > My understanding is there is a significant performance impact when using > reflection to call methods. While the Method.invoke() is reasonably quick, > Class.getMethod() lookup is slow (in an order of magnitude). > My experience has been that reflection processing done by Struts has a vanishingly small impact on overall app performance (although it is definitely more expensive than hard coded method calls). > It's actually possible to cache the java.lang.reflect.Method instances > after the first lookup. Am I right? > Yes, but you don't need to worry about it. > Is such caching necessary and does Struts do this caching? Struts already does it (inside the PropertyUtils class). The first time it encounters a particular bean class, Struts executes: BeanInfo beanInfo = Introspector.getBeanInfo(bean.getClass()); PropertyDescriptor descriptors[] = beanInfo.getPropertyDescriptors(); and caches the descriptors[] array. Each PropertyDescriptor already has a direct reference to the appropriate getter and setter Method objects, so they are in effect being cached as well. The Class.getMethod() call is never ever utilized. > -- > John > Craig
Re: Introspection used in Struts (Was: Bean convention vs. Struts convention)
My understanding is there is a significant performance impact when using reflection to call methods. While the Method.invoke() is reasonably quick, Class.getMethod() lookup is slow (in an order of magnitude). It's actually possible to cache the java.lang.reflect.Method instances after the first lookup. Am I right? Is such caching necessary and does Struts do this caching? -- John At 12:03 PM 8/7/2001 -0700, you wrote: The use of introspection in Struts is totally based on the rules that the JDK implements (in the java.beans.Introspector class). These are in turn based on the naming design patterns in the JavaBeans Specification, which you can grab at: http://java.sun.com/products/javabeans/ Note that the standard JSP tags use exactly the same set of rules. Craig -- John Yu Scioworks Technologies e: [EMAIL PROTECTED] w: +(65) 873 5989 w: http://www.scioworks.com m: +(65) 9782 9610
Re: Bean Introspection and tag
The rule of thumb to follow is that property names should start with a lower case letter. Otherwise you may come up with property names that cannot be made to work with getters and setters. This is illustrated in the answers to your questions below. > So what IS the getter name for this property - "LastName" ? There isn't one. If the method was called getLastName, the rules say that, once 'get' is removed, the first letter should be converted to lower case, so the property name is 'lastName'. The only exception to converting the first letter to lower case is when the second letter is also upper case. > So what IS the getter name for this property - "LASTNAME" => get??? The getter for this is getLASTNAME. Once 'get' is removed, we see that both the first and second letters are upper case, so the name remains unchanged. > So what IS the getter name for this property - "lastname" => get??? The getter for this is getLastname. Again, once 'get' is removed, we convert the first letter to lower case and the property name is 'lastname'. If you stick to property names that use the same convention as for Java variables (i.e. the first letter is lower case, and the first letter of subsequent words is capitalised), then you shouldn't have problems. I hope this helps clarify. -- Martin Cooper - Original Message - From: "Tim Colson" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Sunday, July 08, 2001 6:49 AM Subject: RE: Bean Introspection and tag > Martin - et. al. - > > > What you are seeing is the correct behaviour. > > Hope this helps. > > Thanks for the info - it certainly makes sense, but ultimately you didn't > answer my question, just re-phrased it. ;-) > > "What is the getter name for this property?". > > So what IS the getter name for this property - "LastName" ? > > BTW - Bean introspection feature or not - it could be a hard sell to get > designer folk to write "correct cased properties"... especially if they are > accustomed to using "LastName" and I can't seem to handle that. Makes the > developer guy (me) appear not so smart. > > So what IS the getter name for this property - "LASTNAME" => get??? > So what IS the getter name for this property - "lastname" => get??? > > Thanks! :-) > Timothy > > > - Original Message - > > From: "Tim Colson" <[EMAIL PROTECTED]> > > To: <[EMAIL PROTECTED]> > > Sent: Friday, July 06, 2001 12:12 PM > > Subject: Bean Introspection and tag > > > > > > > As per the bean: struts API docs, I've included an "Employee" > > type object > > > into the request scope called "emp". > > > > > > emp can get/set the "mLastName" property using getLastName() and > > > setLastName() > > > > > > However - when I try the following > > > > > > > > > > > > I'm told that there is no "getter" method > > > javax.servlet.ServletException: No getter method for property > > LastName of > > > bean > > > > > > If I make the property initial lower case, it works fine: > > > > > > > > > > > > The Bean Spec Section 8.8 says this about capitalization: > > > So for example, "FooBah" becomes "fooBah" > > > --- > > > So for example, "LastName" becomes "lastName" > > > I tried adding the accessor "getlastName()" to my Employee class - still > > > fails. > > > > > > Property -> get method: result > > > - > > > "lastName" -> getLastName() : OK > > > "LastName" -> getLastName() : Fails > > > "LastName" -> getlastName() : Fails > > > "LastName" -> get?() > > > > > > I searched the archives and read more of the bean spec - but didn't pull > > up > > > anything useful on this. :-( > > > > > > Thanks, > > > Tim > > > > > > > > > > > > > >
RE: Bean Introspection and tag
Martin - et. al. - > What you are seeing is the correct behaviour. > Hope this helps. Thanks for the info - it certainly makes sense, but ultimately you didn't answer my question, just re-phrased it. ;-) "What is the getter name for this property?". So what IS the getter name for this property - "LastName" ? BTW - Bean introspection feature or not - it could be a hard sell to get designer folk to write "correct cased properties"... especially if they are accustomed to using "LastName" and I can't seem to handle that. Makes the developer guy (me) appear not so smart. So what IS the getter name for this property - "LASTNAME" => get??? So what IS the getter name for this property - "lastname" => get??? Thanks! :-) Timothy > - Original Message - > From: "Tim Colson" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Friday, July 06, 2001 12:12 PM > Subject: Bean Introspection and tag > > > > As per the bean: struts API docs, I've included an "Employee" > type object > > into the request scope called "emp". > > > > emp can get/set the "mLastName" property using getLastName() and > > setLastName() > > > > However - when I try the following > > > > > > > > I'm told that there is no "getter" method > > javax.servlet.ServletException: No getter method for property > LastName of > > bean > > > > If I make the property initial lower case, it works fine: > > > > > > > > The Bean Spec Section 8.8 says this about capitalization: > > So for example, "FooBah" becomes "fooBah" > > --- > > So for example, "LastName" becomes "lastName" > > I tried adding the accessor "getlastName()" to my Employee class - still > > fails. > > > > Property -> get method: result > > - > > "lastName" -> getLastName() : OK > > "LastName" -> getLastName() : Fails > > "LastName" -> getlastName() : Fails > > "LastName" -> get?() > > > > I searched the archives and read more of the bean spec - but didn't pull > up > > anything useful on this. :-( > > > > Thanks, > > Tim > > > > > > >
Re: Bean Introspection and tag
What you are seeing is the correct behaviour. I think the piece of the puzzle you are missing is that, in the part of the JavaBeans spec you are looking at, it says: "Thus when we extract a property or event name *from the middle of an existing Java name*, we normally convert the first character to lower case." For example, when extracting the property name from a method named 'getLastName', the first character is converted to lower case, resulting in the property name 'lastName'. The thing that is a bit confusing is that the JavaBeans spec talks about how to obtain the property name from a method (getter or setter) name, whereas we (at least you and I, anyway!) tend to think of the process the other way around, as in "what is the getter name for this property?". Hope this helps. -- Martin Cooper - Original Message - From: "Tim Colson" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, July 06, 2001 12:12 PM Subject: Bean Introspection and tag > As per the bean: struts API docs, I've included an "Employee" type object > into the request scope called "emp". > > emp can get/set the "mLastName" property using getLastName() and > setLastName() > > However - when I try the following > > > > I'm told that there is no "getter" method > javax.servlet.ServletException: No getter method for property LastName of > bean > > If I make the property initial lower case, it works fine: > > > > The Bean Spec Section 8.8 says this about capitalization: > So for example, "FooBah" becomes "fooBah" > --- > So for example, "LastName" becomes "lastName" > I tried adding the accessor "getlastName()" to my Employee class - still > fails. > > Property -> get method: result > - > "lastName" -> getLastName() : OK > "LastName" -> getLastName() : Fails > "LastName" -> getlastName() : Fails > "LastName" -> get?() > > I searched the archives and read more of the bean spec - but didn't pull up > anything useful on this. :-( > > Thanks, > Tim > >
Bean Introspection and tag
As per the bean: struts API docs, I've included an "Employee" type object into the request scope called "emp". emp can get/set the "mLastName" property using getLastName() and setLastName() However - when I try the following I'm told that there is no "getter" method javax.servlet.ServletException: No getter method for property LastName of bean If I make the property initial lower case, it works fine: The Bean Spec Section 8.8 says this about capitalization: So for example, FooBah becomes fooBah --- So for example, LastName becomes lastName I tried adding the accessor "getlastName()" to my Employee class - still fails. Property -> get method: result - "lastName" -> getLastName() : OK "LastName" -> getLastName() : Fails "LastName" -> getlastName() : Fails "LastName" -> get?() I searched the archives and read more of the bean spec - but didn't pull up anything useful on this. :-( Thanks, Tim
Re: Introspection
Kyle Robinson wrote: > Has anyone used the concept of introspection with the struts > framework? I believe the idea of it is that you write a use bean line > in your jsp and call the > and when the form is posted all the properties of object blah get set > to the values in the form objects that match the names.Tell me if I'm > way off-base and if this is the opposite direction from Struts or > not.Kyle Robinson > Systems Consultant > Pangaea Systems Inc. > (250) 360-0111 Struts does this kind of introspection for you automatically when you use form beans. If you want to use introspection for your own purposes, you will definitely want to check out the following classes in the Struts Javadoc: org.apache.struts.util.BeanUtils org.apache.struts.util.ConvertUtils org.apache.struts.util.PropertyUtils Craig
Introspection
Has anyone used the concept of introspection with the struts framework? I believe the idea of it is that you write a use bean line in your jsp and call the and when the form is posted all the properties of object blah get set to the values in the form objects that match the names. Tell me if I'm way off-base and if this is the opposite direction from Struts or not. Kyle Robinson Systems Consultant Pangaea Systems Inc. (250) 360-0111
Maps and property introspection
Hi, I'm wondering if anyone has modified PropertyUtils to handle "synthetic" properties of Maps. For example, if you have a hashtable, you could mimic "hash.get("somekey")", with: This was a very nice feature of ATG's JHTML implementation. Is there any reason why one would not want to do this in Jsp? Thanks, Nino