开发者

How to set properties to 2 domain objects using a single form and here 1 of the domain objects is acting as formbacking object

I have developed a JSP which is refering to the properties of 2 domain objects. Here i am making one of the objects as domain and trying to set the properties using a Collection object to other domain object. But the the JSP is not getting loaded and giving only one exception that is:

org.springframework.beans.NotReadablePropertyException: Invalid property 'auction' of bean class [com.persistent.eap.domain.Auction]: Bean property 'auction' is 开发者_JS百科not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?


The error sounds like your bean property does not adhere to the java beans standard.

A java beans property must be specified like this:

private [type] [name];
public void set[Name]([type] [name]);
public [type] get[Name]();

if [type] is boolean, then the get method may also (and should) be called

public [type] is[Name]();

Valid examples:

private int foo;
public void setFoo(int foo){this.foo=foo;}
public int getFoo(){return this.foo;}


private boolean bar;
public void setBar(boolean bar){this.bar=bar;}
public boolean isBar(){return this.bar;}

The important things are:

  1. Naming conventions
    • setter name = "set" + field name (first letter capitalized)
    • getter name = "get" + field name (first letter capitalized)
      (or, for boolean fields only): "is" + field name (first letter capitalized)

  2. Correct types
    • setter must have a single parameter of the same type as the field, return type must be void (e.g. fluent setters are not allowed)
    • getter must have no parameters, return type must be field type

Reference:

  • JavaBean conventions (wikipedia)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜