• Post Reply Bookmark Topic Watch Topic
  • New Topic

Wierd Java Beans Problem  RSS feed

 
Muthya Prashant
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I coded a java bean with some int, string properties.
To identify with the name of the field i prefixed all the properties with i/s letters and then the property starts with capital letter.

say:
int iNumber;

generated the getter and setter and to my surprise the iNumber is not being found in the bean,

error messges speaks :
No getter found for the iNumber in the bean.

the reason being,

the way getter and setter are defined.
i dont understand this. Can some one please help me with this.

Prashanth.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where and how are you referencing the properties?

In JavaBeans, the actual name of the internal member variable in which data is stored (if there's any at all!) is completly moot. All that matters is how the mutators (setters) and accessor (getters) are named.

For example, let's say that a bean has as accessor:



and I just happend to store it (remember, it doesn't have to be stored at all, it can be computed on the fly) in a member:



The fact that the internal variable is named schmoo is completely immaterial to the referers of the bean. All they see is that the bean has a property accesor named getLuckyNumber which defines a property of the bean name luckyNumber.

P.S. Using "hungarian notation" such as preceding int variables with "i" and string variables with "s" is not normally something you would see done in Java or in any other strongly-typed language. I'd drop that habit.
[ March 20, 2006: Message edited by: Bear Bibeault ]
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For some reason that I forget, JavaBean properties can't start with a lower-case letter followed by an upper-case letter. So in my case my "eMailAddress" property had to be renamed "emailAddress". So you made an unlucky choice of naming convention. However if you get rid of the Hungarian notation (an idea I agree with), your problem should disappear.
 
ramprasad madathil
Ranch Hand
Posts: 489
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For some reason that I forget, JavaBean properties can't start with a lower-case letter followed by an upper-case letter


Stefan Evans has provided an excellent explanation in this thread in the sun jsp forum.

Reference
---------
java.beans.Introspector: decapitalize.

ram.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!