Back Forum Reply New

Setter error creating charts with jfreechart and IOC

Hi,

I just tried to setup a complete graph configuration with jfreechart 1.0.1 (jfreechart/) and Spring 2 RC3 and received a NotWritablePropertyException for method CategoryPlot.setDomainAxis(CategoryAxis) as follows. I definitely checked in the debug mode of eclipse (at the supplied line) that the rootBean is the correct CategoryPlot and that the calculated setter method (setDomainAxis) is correctly as well.Code:
org..beans.NotWritablePropertyException: Invalid property 'domainAxis' of bean class [org.jfree.chart.plot.CategoryPlot]: Bean property 'domainAxis' is not writable or has an invalid setter method. Did you mean 'domainAxes'?
at org..beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:746)
at org..beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:606)
Following the configuration allowing for a complete setup of a bar chart with JFreeChart.Code:
lt;?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?gt;

lt;beans xmlns=quot;schema/beansquot; xmlns:xsi=quot;2001/XMLSchema-instancequot;
xmlns:util=quot;schema/utilquot;
xsi:schemaLocation=quot;
schema/beans schema/beans/spring-beans.xsd
schema/util schema/util/spring-util.xsdquot;gt;

lt;bean id=quot;blackColorquot; class=quot;java.awt.Colorquot; scope=quot;singletonquot;gt;
lt;constructor-arg value=quot;0quot; /gt;
lt;constructor-arg value=quot;0quot; /gt;
lt;constructor-arg value=quot;0quot; /gt;
lt;/beangt;

lt;bean id=quot;whiteColorquot; class=quot;java.awt.Colorquot; scope=quot;singletonquot;gt;
lt;constructor-arg value=quot;255quot; /gt;
lt;constructor-arg value=quot;255quot; /gt;
lt;constructor-arg value=quot;255quot; /gt;
lt;/beangt;

lt;bean id=quot;gridlineStrokequot; class=quot;java.awt.BasicStrokequot; scope=quot;singletonquot;gt;
lt;constructor-arg value=quot;1quot; /gt;
lt;/beangt;

lt;alias alias=quot;barOutlineStrokequot; name=quot;gridlineStrokequot; /gt;

lt;bean id=quot;axisStrokequot; class=quot;java.awt.BasicStrokequot; scope=quot;singletonquot;gt;
lt;constructor-arg value=quot;2quot; /gt;
lt;/beangt;

lt;bean id=quot;axisLabelFontquot; class=quot;java.awt.Fontquot;gt;
lt;constructor-arg value=quot;Arialquot; /gt;
lt;constructor-arggt;
lt;util:constant static-field=quot;java.awt.Font.PLAINquot; /gt;
lt;/constructor-arggt;
lt;constructor-arg value=quot;11quot; /gt;
lt;/beangt;

lt;alias alias=quot;axisTickLabelFontquot; name=quot;axisLabelFontquot; /gt;

lt;util:constant id=quot;defaultCategoryLabelPositionsquot;
static-field=quot;org.jfree.chart.axis.CategoryLabelPositions.UP_90quot; /gt;

lt;util:constant id=quot;defaultOrientationquot; static-field=quot;org.jfree.chart.plot.PlotOrientation.VERTICALquot; /gt;

lt;bean id=quot;defaultBarRendererquot; class=quot;org.jfree.chart.renderer.category.BarRendererquot; scope=quot;prototypequot;gt;
lt;property name=quot;drawBarOutlinequot; value=quot;truequot; /gt;
lt;property name=quot;outlineStrokequot; ref=quot;barOutlineStrokequot; /gt;
lt;property name=quot;outlinePaintquot; ref=quot;blackColorquot; /gt;
lt;/beangt;

lt;bean id=quot;defaultStackedBarRendererquot; class=quot;org.jfree.chart.renderer.category.StackedBarRendererquot;
scope=quot;prototypequot;gt;
lt;property name=quot;drawBarOutlinequot; value=quot;truequot; /gt;
lt;property name=quot;outlineStrokequot; ref=quot;barOutlineStrokequot; /gt;
lt;property name=quot;outlinePaintquot; ref=quot;blackColorquot; /gt;
lt;/beangt;

lt;bean id=quot;defaultCategoryAxisquot; class=quot;org.jfree.chart.axis.CategoryAxisquot; scope=quot;prototypequot;gt;
lt;property name=quot;axisLineStrokequot; ref=quot;axisStrokequot; /gt;
lt;property name=quot;axisLinePaintquot; ref=quot;blackColorquot; /gt;
lt;property name=quot;labelFontquot; ref=quot;axisLabelFontquot; /gt;
lt;property name=quot;tickLabelFontquot; ref=quot;axisTickLabelFontquot; /gt;
lt;property name=quot;categoryLabelPositionsquot; ref=quot;defaultCategoryLabelPositionsquot; /gt;
lt;/beangt;

lt;bean id=quot;defaultValueAxisquot; class=quot;org.jfree.chart.axis.NumberAxisquot; scope=quot;prototypequot;gt;
lt;property name=quot;positiveArrowVisiblequot; value=quot;truequot; /gt;
lt;property name=quot;axisLineStrokequot; ref=quot;axisStrokequot; /gt;
lt;property name=quot;axisLinePaintquot; ref=quot;blackColorquot; /gt;
lt;property name=quot;labelFontquot; ref=quot;axisLabelFontquot; /gt;
lt;property name=quot;tickLabelFontquot; ref=quot;axisTickLabelFontquot; /gt;
lt;/beangt;

lt;bean id=quot;testBarChartquot; class=quot;org.jfree.chart.plot.CategoryPlotquot; scope=quot;prototypequot;gt;
lt;property name=quot;domainAxisquot; ref=quot;defaultCategoryAxisquot; /gt;
lt;property name=quot;domainGridLinesVisiblequot; value=quot;falsequot; /gt;
lt;property name=quot;rangeAxisquot; ref=quot;defaultValueAxisquot; /gt;
lt;property name=quot;rangeGridlineStrokequot; ref=quot;gridlineStrokequot; /gt;
lt;property name=quot;rangeGridlinePaintquot; ref=quot;blackColorquot; /gt;
lt;property name=quot;orientationquot; ref=quot;defaultOrientationquot; /gt;
lt;property name=quot;backgroundPaintquot; ref=quot;whiteColorquot; /gt;
lt;property name=quot;outlinePaintquot; value=quot;nullquot; /gt;
lt;property name=quot;rendererquot; ref=quot;defaultBarRendererquot; /gt;
lt;/beangt;

lt;/beansgt;
Please help anyone if you can. If you need help installing jfreechart just contact me.

I forgot to mention that I am using this in context of a current Java 5.

The workaround to this quot;bugquot; is to use the domainAxes property which has the  same purpose but with an array. Note that the other property definitely exists. After the workaround that there are still real errors in the above xml that pop up. Simply follow the proposal there.

Then the property quot;rangeAxisquot; produces the same error, same workaround is quot;rangeAxesquot; (as proposed by spring). The same with property quot;rendererquot; and workaround quot;renderersquot;. Strangely the array setters work but the single argument setters don't.

I just figured out that a similar error occurs trying to set the nested properties like quot;legend.borderquot; of org.jfree.chart.JFreeChart when those PropertyDescriptors say they don't know any Getter of the name quot;legendquot;. Well, it exisits.

I stepped through my debugger figuring out the following:

BeanWrapperImpl.java:507 does the following.

Code:
PropertyDescriptor pd = getPropertyDescriptorInternal(tokens.actualName);
if (pd == null || pd.getReadMethod() == null) {
throw new NotReadablePropertyException(getRootClass(), this.nestedPath + propertyName);
}
getReadMethod now returns null for property JFreeChart.(get/set)Legend. I add an expression in my debugger as follows:

Code:
quot;pd.getReadMethod()quot;= null
Right! That's why the exception occurs. But when I look at the pd variable I notice that the actual type of it is java.beans.IndexedPropertyDescriptor. Now I add the following expression:Code:
quot;((java.beans.IndexedPropertyDescriptor) pd).getIndexedReadMethod()quot;= Method  (id=1623)
Well and this method says it's name is quot;getLegendquot;. What do you think? Bug? And why does it happen with some bean classes but with others not?

I just managed to find a solution for the problem. See this bug I posted for further details:

proj...s#action_19445

Summary:
if you have the two getters
bean.getProperty() and
bean.getProperty(int index)
Spring doesn't recognize that Introspection delivers two property descriptors with the name quot;propertyquot;. As spring ignores the existence of IndexedPropertyDescriptors it is just random per property wether getReadProperty() fails or not (depeding on the sort order of the property descriptors coming in). If the indexed property comes last it will overwrite the normal one and thus you get errors though the property you search for exists.

Though this bug is yet to be fixed and seems to apply to all spring versions before. Strange that it didn't pop up up to this day.

hi,
I just need to implement code like yours shown in this post. Can you pls help?

thanks,
divyajun
¥
Back Forum Reply New