permaculture playing cards*
The moose likes Java in General and the fly likes PropertyUtils getSimpleProperty not working for variables which have capital letters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "PropertyUtils getSimpleProperty not working for variables which have capital letters" Watch "PropertyUtils getSimpleProperty not working for variables which have capital letters" New topic
Author

PropertyUtils getSimpleProperty not working for variables which have capital letters

Pawan Kalyan
Ranch Hand

Joined: Jun 18, 2009
Posts: 34
Hi ,

I am trying to use reflection to get a property value from a bean using and is working fine for most of the variables.



but i am getting a run time error for few variables like etc.

Exception in thread "main" java.lang.NoSuchMethodException: Unknown property 'iPANCardNumber' on class 'class com.Person'

I was wondering if PropertyUtils doesnt like the variables with firs letter in lowercase and the next letter in upper case and wanted to get some help in this regard.

Please let me know if anyone needs more info regarding my problem and appreciate your help here.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38474
    
  23
What is PropertyUtils?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38474
    
  23
If you are using reflection, it si worth checking all the methods in that Person class. Maybe it is called iPanCardNumber
Pawan Kalyan
Ranch Hand

Joined: Jun 18, 2009
Posts: 34
PropertyUtils is from org.apache.commons.beanutils.PropertyUtils. I have the variable name as iPANCardNumber and there are a bunch of beans with variable names similar to iPANCardNumber and i cant change the case of all those variables.

Hope that helps.
Pawan Kalyan
Ranch Hand

Joined: Jun 18, 2009
Posts: 34
any more suggestions or ideas how to fix this issue ?
Pawan Kalyan
Ranch Hand

Joined: Jun 18, 2009
Posts: 34
are there any rules or specifications to name java class variables which are compatible for BeanUtils.getProperty like the first x number of letters should be in lower case etc etc.. ?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38474
    
  23
If it is a variable name, why does the error message talk about methods?

Don’t know any more than that. Sorry.
Pawan Kalyan
Ranch Hand

Joined: Jun 18, 2009
Posts: 34
because i have getter and setter methods for that variable and i guess BeanUtils does work on getter methods but not sure if does expect the method names in a particular way like first letter should be in lower case or 2nd letter should be lower case etc etc..
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Yes, that's a well-known "feature" of the Java Bean spec. Usually people encounter it when they try to use "eMailAddress" as a property name but your example works just as well.

It isn't that the property name has capital letters, it's that the first letter is lower-case and the second is upper-case.
 
wood burning stoves
 
subject: PropertyUtils getSimpleProperty not working for variables which have capital letters