Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / JavaBeans / August 2005

Tip: Looking for answers? Try searching our database.

Beanutils.getArrayProperty throws NoSuchMethodException for valid method

Thread view: 
O.B. - 24 Aug 2005 04:06 GMT
I'm getting an odd problem when executing the Beanutils.getArrayProperty on
an attribute that I know exists.  See the example below (TestClass.java and
TestBean.java).  What am I doing wrong?

java.lang.NoSuchMethodException: Unknown property 'vTRate1'
         at
org.apache.commons.beanutils.PropertyUtils.getSimpleProperty(PropertyUtils.java:1175)
         at
org.apache.commons.beanutils.PropertyUtils.getNestedProperty(PropertyUtils.java:772)
         at
org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:801)
         at
org.apache.commons.beanutils.BeanUtils.getArrayProperty(BeanUtils.java:450)
         at com.dyn.beantest.TestClass.print(TestClass.java:16)
         at com.dyn.beantest.TestClass.main(TestClass.java:46)

TestClass.java:
package com.dyn.beantest;

import java.io.PrintStream;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import org.apache.commons.beanutils.BeanUtils;

public class TestClass {
    public TestClass() {
    }

    public void print(TestBean theBean) {
       try {
          List exportFields = TestBean.getAttributeList();
          for (int j = 0; j < exportFields.size(); j++) {
             String[] val = BeanUtils.getArrayProperty(
                       theBean, (String) exportFields.get(j));
             if (null != val) {
                for (int k = 0; k < val.length; k++) {
                   String value = null != val[k] ? val[k] : "";
                   System.out.print(value);
                   if ((k + 1) < val.length) {
                      System.out.print(",");
                   }
                }
             }
             if ((j + 1) < exportFields.size()) {
                System.out.print(",");
             }
          }
       } catch (IllegalAccessException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
       } catch (InvocationTargetException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
       } catch (NoSuchMethodException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
       }
    }

    public static void main(String[] args) {
       TestBean myBean = new TestBean();
       TestClass thisTest = new TestClass();
       thisTest.print(myBean);
    }
}

TestBean.java:
package com.dyn.beantest;

import java.util.LinkedList;
import java.util.List;

public class TestBean {
    private String testName;
    private String vTRate1;
    private String vTRate1Check;

    public TestBean() {
    }

    public TestBean(String testName) {
       this.testName = testName;
    }

    public static List getAttributeList() {
       List attributeList = new LinkedList();
       attributeList.add("testName");
       attributeList.add("vTRate1");
       attributeList.add("vTRate1Check");
       return attributeList;
    }

    public String getTestName() {
       return testName;
    }

    public void setTestName(String testName) {
       this.testName = testName;
    }

    public String getVTRate1() {
       return vTRate1;
    }

    public void setVTRate1(String rate1) {
       vTRate1 = rate1;
    }

    public String getVTRate1Check() {
       return vTRate1Check;
    }

    public void setVTRate1Check(String rate1Check) {
       vTRate1Check = rate1Check;
    }
}
Thomas Hawtin - 24 Aug 2005 11:08 GMT
> I'm getting an odd problem when executing the Beanutils.getArrayProperty
> on an attribute that I know exists.  See the example below
[quoted text clipped - 15 lines]
>        return vTRate1;
>     }

Should that not be vtRate1 and vtRate1Check?

You should be able to get all the property names from
java.beans.Introspector.getBeanInfo.getPropertyDescriptors.

Tom Hawtin
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/

O.B. - 24 Aug 2005 13:41 GMT
>>I'm getting an odd problem when executing the Beanutils.getArrayProperty
>>on an attribute that I know exists.  See the example below
[quoted text clipped - 23 lines]
>
> Tom Hawtin

Very odd.  Why does it not allow the 2nd letter of a class attribute to be
capitalized?
Thomas Hawtin - 24 Aug 2005 13:58 GMT
> Very odd.  Why does it not allow the 2nd letter of a class attribute to
> be capitalized?

I forget the exact rules, but sequences of capital letters are assumed
to constitute one word (except the last character). Actually sequences
of capital letters right at the front of names may be treated differently.

Tom Hawtin
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.