Announcement Announcement Module
Collapse
No announcement yet.
Second character upper case Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Second character upper case

    Hello:
    I have a bean as shown in the snipper below:
    There are 2 fields:

    sECOND // the second character is upper case
    thIRD // the third character is upper case.

    In the main method() i use the following code to get the value of sECOND and thIRD property but get the error for the sECOND filed but the thIRD field is good.

    The exception I get is :
    thIRD third
    org.springframework.beans.NotReadablePropertyExcep tion: Invalid property 'sECOND' of bean class [com.savvion.bo.TCase]: Bean property 'sECOND' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
    at org.springframework.beans.BeanWrapperImpl.getPrope rtyValue(BeanWrapperImpl.java:510)
    at org.springframework.beans.BeanWrapperImpl.getPrope rtyValue(BeanWrapperImpl.java:502)
    at com.savvion.bo.TCase.main(TCase.java:25)

    I'm new to Spring and using version 2. Could some one tell me what I may be doing wrong.

    Thanks cbear

    Code:

    package test;

    import org.springframework.beans.BeanWrapper;
    import org.springframework.beans.BeanWrapperImpl;

    public class TCase {

    private String sECOND= "sECOND";
    private String thIRD = "thIRD";

    public TCase(String second, String thIRD) {
    super();
    sECOND = second;
    this.thIRD = thIRD;
    }

    /**
    * @param args
    */
    public static void main(String[] args) {
    try{
    TCase tc = new TCase("second","third" );
    BeanWrapper bwComp = new BeanWrapperImpl(tc);
    System.out.println("thIRD " + bwComp.getPropertyValue("thIRD"));
    System.out.println("sECOND is "+ bwComp.getPropertyValue("sECOND"));
    }catch(Throwable th){
    th.printStackTrace();
    }

    }

    public String getSECOND() {
    return sECOND;
    }

    public void setSECOND(String second) {
    sECOND = second;
    }

    public String getThIRD() {
    return thIRD;
    }

    public void setThIRD(String thIRD) {
    this.thIRD = thIRD;
    }

    }

  • #2
    You ran into one of the special cases of the naming syntax of bean properties (as specified by the JavaBeans specification). Change the lookup to SECOND and it should work.

    Comment


    • #3
      As Marten said take a look at the JavaBean spec, that should answer you questions. One point however is it doesn't matter what the property is called internally, it's the getter/setter names that are the important bit.

      Comment


      • #4
        Thanks Martin/Karl. I will try it out based on the specification.

        Comment

        Working...
        X