Bean Introspection: attributes starting with a single letter.
This issue came up in a post on the JSP forum:
http://forum.java.sun.com/thread.jspa?threadID=702445&tstart=0
Basically it comes down to this.
Given a bean in which we have methods getXPosition(), setXPosition().
According to everything I had thought up until today, this would reveal an attribute called "xPosition" (ie starting with a lower case 'x')
However running the Introspector over this, it turns out that the attribute revealed is "XPosition"
Is this correct?
Can anyone point me to where the javabeans specification is that documents this functionality (I've had a look, but can't find exactly what I am looking for)
The example class:
MapPoint.java
package com.my.bean;
publicclass MapPoint{
privateint xPosition;
publicint getXPosition(){
return xPosition;
}
publicvoid setXPosition(int position){
xPosition = position;
}
publicint getX(){
return xPosition;
}
publicvoid setX(int x){
this.xPosition = x;
}
}
My simple introspection class
TestBeanInfo.java
package com.my.bean;
import java.beans.BeanInfo;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
publicclass TestBeanInfo{
public TestBeanInfo(){
try{
MapPoint mapPoint =new MapPoint();
mapPoint.setXPosition(10);
BeanInfo info = Introspector.getBeanInfo(mapPoint.getClass());
PropertyDescriptor[] props = info.getPropertyDescriptors();
for (int i = 0; i < props.length; i++){
System.out.print("Property " + i +" = " + props[i].getName());
System.out.print("\t Read = " + (props[i].getReadMethod() !=null ?"Yes" :"No"));
System.out.println("\t Write = " + (props[i].getWriteMethod() !=null ?"Yes" :"No"));
}
}
catch (Exception e){
System.out.println("Error " + e.getMessage());
e.printStackTrace(System.out);
}
}
publicstaticvoid main(String[] args){
new TestBeanInfo();
}
}
Cheers,
evnafets

