Announcement Announcement Module
Collapse
No announcement yet.
Setter error creating charts with jfreechart and IOC Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Setter error creating charts with jfreechart and IOC

    Hi,

    I just tried to setup a complete graph configuration with jfreechart 1.0.1 (http://www.jfree.org/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.springframework.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.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:746)
    	at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:606)
    Following the configuration allowing for a complete setup of a bar chart with JFreeChart.

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    
    <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns:util="http://www.springframework.org/schema/util"
    	xsi:schemaLocation="
    		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    		http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
    
    	<bean id="blackColor" class="java.awt.Color" scope="singleton">
    		<constructor-arg value="0" />
    		<constructor-arg value="0" />
    		<constructor-arg value="0" />
    	</bean>
    
    	<bean id="whiteColor" class="java.awt.Color" scope="singleton">
    		<constructor-arg value="255" />
    		<constructor-arg value="255" />
    		<constructor-arg value="255" />
    	</bean>
    
    	<bean id="gridlineStroke" class="java.awt.BasicStroke" scope="singleton">
    		<constructor-arg value="1" />
    	</bean>
    
    	<alias alias="barOutlineStroke" name="gridlineStroke" />
    
    	<bean id="axisStroke" class="java.awt.BasicStroke" scope="singleton">
    		<constructor-arg value="2" />
    	</bean>
    
    	<bean id="axisLabelFont" class="java.awt.Font">
    		<constructor-arg value="Arial" />
    		<constructor-arg>
    			<util:constant static-field="java.awt.Font.PLAIN" />
    		</constructor-arg>
    		<constructor-arg value="11" />
    	</bean>
    
    	<alias alias="axisTickLabelFont" name="axisLabelFont" />
    
    	<util:constant id="defaultCategoryLabelPositions"
    		static-field="org.jfree.chart.axis.CategoryLabelPositions.UP_90" />
    
    	<util:constant id="defaultOrientation" static-field="org.jfree.chart.plot.PlotOrientation.VERTICAL" />
    
    	<bean id="defaultBarRenderer" class="org.jfree.chart.renderer.category.BarRenderer" scope="prototype">
    		<property name="drawBarOutline" value="true" />
    		<property name="outlineStroke" ref="barOutlineStroke" />
    		<property name="outlinePaint" ref="blackColor" />
    	</bean>
    
    	<bean id="defaultStackedBarRenderer" class="org.jfree.chart.renderer.category.StackedBarRenderer"
    		scope="prototype">
    		<property name="drawBarOutline" value="true" />
    		<property name="outlineStroke" ref="barOutlineStroke" />
    		<property name="outlinePaint" ref="blackColor" />
    	</bean>
    
    	<bean id="defaultCategoryAxis" class="org.jfree.chart.axis.CategoryAxis" scope="prototype">
    		<property name="axisLineStroke" ref="axisStroke" />
    		<property name="axisLinePaint" ref="blackColor" />
    		<property name="labelFont" ref="axisLabelFont" />
    		<property name="tickLabelFont" ref="axisTickLabelFont" />
    		<property name="categoryLabelPositions" ref="defaultCategoryLabelPositions" />
    	</bean>
    
    	<bean id="defaultValueAxis" class="org.jfree.chart.axis.NumberAxis" scope="prototype">
    		<property name="positiveArrowVisible" value="true" />
    		<property name="axisLineStroke" ref="axisStroke" />
    		<property name="axisLinePaint" ref="blackColor" />
    		<property name="labelFont" ref="axisLabelFont" />
    		<property name="tickLabelFont" ref="axisTickLabelFont" />
    	</bean>
    
    	<bean id="testBarChart" class="org.jfree.chart.plot.CategoryPlot" scope="prototype">
    		<property name="domainAxis" ref="defaultCategoryAxis" />
    		<property name="domainGridLinesVisible" value="false" />
    		<property name="rangeAxis" ref="defaultValueAxis" />
    		<property name="rangeGridlineStroke" ref="gridlineStroke" />
    		<property name="rangeGridlinePaint" ref="blackColor" />
    		<property name="orientation" ref="defaultOrientation" />
    		<property name="backgroundPaint" ref="whiteColor" />
    		<property name="outlinePaint" value="null" />
    		<property name="renderer" ref="defaultBarRenderer" />
    	</bean>
    
    </beans>
    Please help anyone if you can. If you need help installing jfreechart just contact me.
    Last edited by Pvblivs; Sep 7th, 2006, 08:02 AM. Reason: Changed title to be more informative

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

    Comment


    • #3
      The workaround to this "bug" 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 "rangeAxis" produces the same error, same workaround is "rangeAxes" (as proposed by spring). The same with property "renderer" and workaround "renderers". Strangely the array setters work but the single argument setters don't.

      Comment


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

        Comment


        • #5
          Possible Solution (but no workaround, this is a bug that must be fixed)

          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:
          "pd.getReadMethod()"= 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:
          "((java.beans.IndexedPropertyDescriptor) pd).getIndexedReadMethod()"= Method  (id=1623)
          Well and this method says it's name is "getLegend". What do you think? Bug? And why does it happen with some bean classes but with others not?

          Comment


          • #6
            Solution found - bug yet to be fixed

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

            http://opensource.atlassian.com/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 "property". 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.
            Last edited by Pvblivs; Sep 7th, 2006, 09:47 AM.

            Comment


            • #7
              need help

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

              thanks,
              divyajun

              Comment

              Working...
              X