-
Enhancement
-
Resolution: Won't Fix
-
P4
-
1.3.1_09
-
generic
-
generic
Name: dk106046 Date: 08/03/2004
Customer's application receives an servlet exception, such as,
Servlet Error-[No getter method for property cardHolders of bean customerForm]:
javax.servlet.jsp.JspException: No getter method for property cardHolders of bean customerForm
The above error is observed when the customer defines the setter/getter method for the property cardHolders of type Collection as a normal property and as also an indexed property as indicated in the following code snippet:
-----code snippet start----
private Collection cardHolders;
....
public java.util.Collection getCardHolders(){
if (cardHolders == null) setCardHolders(new ArrayList());
return cardHolders;
}
public void setCardHolders(Collection cardHolders){
this.cardHolders = cardHolders;
}
public Customer getCardHolders(int i){
Customer cust = null;
if (cardHolders == null)
cust = (Customer)((ArrayList)this.cardHolders).get(i);
return cust;
}
public void setCardHolders(int i, Customer newCust){
((ArrayList)this.cardHolders).set(i, newCust);
}
-----code snippet end----
- Any additional information
This problem is not found with level earlier to 1.3.1_08. This is due
to the fix for Sun bug id 4477877.
Further, Per the Sun beans specification:
----start extract-------------------
Indexed properties
If we find a property whose type is an array “<PropertyElement>[]”, then we also look for methods of the form:
public < PropertyElement> get< PropertyName>(int a);
public void set< PropertyName>(int a, < PropertyElement> b);
If we find either kind of pattern then we assume that “<propertyName>” is an indexed property and that these methods can be used to read and/or write an indexed value. Thus an indexed property “foo” might be represented by four accessor methods:
public Bah[] getFoo();
public void setFoo(Bah a[]);
public Bah getFoo(int a);
public void setFoo(int a, Bah b);
------end extract-------------------
However, we find that the property "cardHolders" is of type Collection which, IMHO, neither this would be considered as a Indexed property (as per the above spec), nor qualifies as a simple property, since there are overloaded setter/getter methods or due to the property type in itself
Alternate Testcase (with List Type)
import java.util.*;
import java.beans.*;
public class PropertyDescriptorTest {
static class TestBean {
private List list;
public void setList(List list){
this.list = list;
}
public List getList(){
return list;
}
public Object getList(int index){
return list.get(index);
}
public void setList(int index, Object bean){
list.set(index, bean);
}
}
public static void main(String[] args) throws Exception{
TestBean testBean = new TestBean();
BeanInfo beanInfo = Introspector.getBeanInfo(TestBean.class);
PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors();
for (int i = 0; i < descriptors.length; i++) {
System.out.println(i);
System.out.println(descriptors[i].getName());
System.out.println(descriptors[i].getPropertyType());
System.out.println(descriptors[i].getReadMethod());
System.out.println(descriptors[i].getWriteMethod());
System.out.println();
}
}
}
======================================================================
Customer's application receives an servlet exception, such as,
Servlet Error-[No getter method for property cardHolders of bean customerForm]:
javax.servlet.jsp.JspException: No getter method for property cardHolders of bean customerForm
The above error is observed when the customer defines the setter/getter method for the property cardHolders of type Collection as a normal property and as also an indexed property as indicated in the following code snippet:
-----code snippet start----
private Collection cardHolders;
....
public java.util.Collection getCardHolders(){
if (cardHolders == null) setCardHolders(new ArrayList());
return cardHolders;
}
public void setCardHolders(Collection cardHolders){
this.cardHolders = cardHolders;
}
public Customer getCardHolders(int i){
Customer cust = null;
if (cardHolders == null)
cust = (Customer)((ArrayList)this.cardHolders).get(i);
return cust;
}
public void setCardHolders(int i, Customer newCust){
((ArrayList)this.cardHolders).set(i, newCust);
}
-----code snippet end----
- Any additional information
This problem is not found with level earlier to 1.3.1_08. This is due
to the fix for Sun bug id 4477877.
Further, Per the Sun beans specification:
----start extract-------------------
Indexed properties
If we find a property whose type is an array “<PropertyElement>[]”, then we also look for methods of the form:
public < PropertyElement> get< PropertyName>(int a);
public void set< PropertyName>(int a, < PropertyElement> b);
If we find either kind of pattern then we assume that “<propertyName>” is an indexed property and that these methods can be used to read and/or write an indexed value. Thus an indexed property “foo” might be represented by four accessor methods:
public Bah[] getFoo();
public void setFoo(Bah a[]);
public Bah getFoo(int a);
public void setFoo(int a, Bah b);
------end extract-------------------
However, we find that the property "cardHolders" is of type Collection which, IMHO, neither this would be considered as a Indexed property (as per the above spec), nor qualifies as a simple property, since there are overloaded setter/getter methods or due to the property type in itself
Alternate Testcase (with List Type)
import java.util.*;
import java.beans.*;
public class PropertyDescriptorTest {
static class TestBean {
private List list;
public void setList(List list){
this.list = list;
}
public List getList(){
return list;
}
public Object getList(int index){
return list.get(index);
}
public void setList(int index, Object bean){
list.set(index, bean);
}
}
public static void main(String[] args) throws Exception{
TestBean testBean = new TestBean();
BeanInfo beanInfo = Introspector.getBeanInfo(TestBean.class);
PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors();
for (int i = 0; i < descriptors.length; i++) {
System.out.println(i);
System.out.println(descriptors[i].getName());
System.out.println(descriptors[i].getPropertyType());
System.out.println(descriptors[i].getReadMethod());
System.out.println(descriptors[i].getWriteMethod());
System.out.println();
}
}
}
======================================================================