如何顯示實現動態bean的setXXX/getXXX方法。

hgwnet發表於2005-03-01
如下程式碼實現動態bean:
DynaProperty[] props = new DynaProperty[]{new DynaProperty("age", int.class), new DynaProperty("name", java.lang.String.class)};
BasicDynaClass comClass = new BasicDynaClass("newBean", null, props);
DynaBean comBean = comClass.newInstance();
BeanUtils.setProperty(comBean, "name", "jone");
BeanUtils.setProperty(comBean, "age", "100");
BeanUtils.setProperty(comBean, "age", "1024264560");
debug("name:" + BeanUtils.getProperty(comBean, "name"));
debug("age:" + BeanUtils.getProperty(comBean, "age"));
執行正常,似乎setXXX和getXXX方法實現了。但現在tapestry中將comBean引數放入tapestry中,該系統會自動呼叫setAge()和getAge()方法,但系統丟擲Exception:ognl.NoSuchPropertyException:age,說明動態bean的age屬性並未被tapestry識別。該如何解決呢?

相關文章