问题
I have Java bean with the field activeRecord
private Boolean activeRecord;
@Override
public Boolean isActiveRecord() {
return activeRecord;
}
@Override
public void setActiveRecord(Boolean activeRecord) {
this.activeRecord = activeRecord;
}
when I send it in List as Jasper Report data source
List<Branch> dataList = new BranchLogic().selectAll();
JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(dataList);
I get the error message
net.sf.jasperreports.engine.JRException: Error retrieving field value from bean: activeRecord. .... Caused by: java.lang.NoSuchMethodException: Property 'activeRecord' has no getter method in class 'class com.tawaak.app.data.domain.model.branch.Branch'
Why Jasper doesn't recognize the isActiveRecord as a getter method?
回答1:
The prefix is... can be used for methods that return a primitive boolean. However, your field activeRecord is of type Boolean, which is an object (the wrapper type of boolean), and for objects you always need to use get....
From the JavaBeans specification, 8.3.2:
In addition, for
booleanproperties, we allow a getter method to match the pattern:public boolean is<PropertyName>();This
is<PropertyName>method may be provided instead of aget<PropertyName>method, or it may be provided in addition to aget<PropertyName>method.
As such, you have two possible fix:
- Make your
activeRecordabooleanand keep the getterisActiveRecord(). This would be the preferred approach ifactiveRecordcannot benull. - Keep it as a
Boolean, but rename your methodisActiveRecord()togetActiveRecord(). You'll need to make sure the caller handlesnullproperly.
来源:https://stackoverflow.com/questions/39307379/java-bean-specifications-for-boolean-field