You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Maliwei <ml...@gmail.com> on 2012/11/02 06:08:27 UTC

Is it a bug or mechanism changing of OGNL, could't set and get a bean's property, that the name of the property's sencond character is upper-case?

As I have desc in the mail title, and see the code below:

/**--------------code start----------**/
import ognl.Ognl;
import ognl.OgnlException;
class Hello {
    private String pName;
    public String getpName() {
        return pName;
    }
    public void setpName(String pName) {
        this.pName = pName;
    }
}

public class OgnlTest {
    public static void main(String[] args) {
        Hello action = new Hello();
        action.setpName("pName.Foo");
        try {
            Object pName = Ognl.getValue("pName", action);
            System.out.println(pName);
        } catch (OgnlException e) {
            //this will happen when use version 2.7+ and 3.x
            e.printStackTrace();
        }
    }
}
/**--------------code end----------**/

According to JavaBeans Spec sec 8.8 "Capitalization of inferred names":
Thus when we extract a property or event name from the middle of an existing Java name, we normally convert the first character to lower case. However to support the occasional use of all upper-case names, we check if the first two characters of the name are both upper case and if so leave it alone. So for example,
“FooBah” becomes “fooBah”
“Z” becomes “z”
“URL” becomes “URL”
We provide a method Introspector.decapitalize which implements this conversion rule.
String java.beans.Introspector.decapitalize(String name)
Utility method to take a string and convert it to normal Java variable name capitalization. This normally means converting the first character from upper case to lower case, but in the (unusual) special case when there is more than one character and both the first and second characters are upper case, we leave it alone. 
Thus "FooBah" becomes "fooBah" and "X" becomes "x", but "URL" stays as "URL".





Best Regards
Ma Liwei

Re: Re: Is it a bug or mechanism changing of OGNL, could't set and get a bean's property, that the name of the property's sencond character is upper-case?

Posted by Maliwei <ml...@gmail.com>.
No, according to spec : if the getter name is "getPName", we can reverse inference  that the property name should be "PName".

ps: I also think the rule of spec is a bit of strange, but if spec not , we'll got a conflict on when property name between "URL" and "uRL".


From: Dave Newton
Date: 2012-11-02 13:58
To: Commons Users List; mlw5415
Subject: Re: Is it a bug or mechanism changing of OGNL, could't set and get a bean's property, that the name of the property's sencond character is upper-case?
Shouldn't the getter be named "getPName"?
Dave
(pardon brevity, typos, and top-quoting; on cell)
On Nov 2, 2012 1:09 AM, "Maliwei" <ml...@gmail.com> wrote:

As I have desc in the mail title, and see the code below:

/**--------------code start----------**/
import ognl.Ognl;
import ognl.OgnlException;
class Hello {
    private String pName;
    public String getpName() {
        return pName;
    }
    public void setpName(String pName) {
        this.pName = pName;
    }
}

public class OgnlTest {
    public static void main(String[] args) {
        Hello action = new Hello();
        action.setpName("pName.Foo");
        try {
            Object pName = Ognl.getValue("pName", action);
            System.out.println(pName);
        } catch (OgnlException e) {
            //this will happen when use version 2.7+ and 3.x
            e.printStackTrace();
        }
    }
}
/**--------------code end----------**/

According to JavaBeans Spec sec 8.8 "Capitalization of inferred names":
Thus when we extract a property or event name from the middle of an existing Java name, we normally convert the first character to lower case. However to support the occasional use of all upper-case names, we check if the first two characters of the name are both upper case and if so leave it alone. So for example,
“FooBah” becomes “fooBah”
“Z” becomes “z”
“URL” becomes “URL”
We provide a method Introspector.decapitalize which implements this conversion rule.
String java.beans.Introspector.decapitalize(String name)
Utility method to take a string and convert it to normal Java variable name capitalization. This normally means converting the first character from upper case to lower case, but in the (unusual) special case when there is more than one character and both the first and second characters are upper case, we leave it alone.
Thus "FooBah" becomes "fooBah" and "X" becomes "x", but "URL" stays as "URL".





Best Regards
Ma Liwei

Re: Is it a bug or mechanism changing of OGNL, could't set and get a bean's property, that the name of the property's sencond character is upper-case?

Posted by Dave Newton <da...@gmail.com>.
Shouldn't the getter be named "getPName"?

Dave

(pardon brevity, typos, and top-quoting; on cell)
On Nov 2, 2012 1:09 AM, "Maliwei" <ml...@gmail.com> wrote:

> As I have desc in the mail title, and see the code below:
>
> /**--------------code start----------**/
> import ognl.Ognl;
> import ognl.OgnlException;
> class Hello {
>     private String pName;
>     public String getpName() {
>         return pName;
>     }
>     public void setpName(String pName) {
>         this.pName = pName;
>     }
> }
>
> public class OgnlTest {
>     public static void main(String[] args) {
>         Hello action = new Hello();
>         action.setpName("pName.Foo");
>         try {
>             Object pName = Ognl.getValue("pName", action);
>             System.out.println(pName);
>         } catch (OgnlException e) {
>             //this will happen when use version 2.7+ and 3.x
>             e.printStackTrace();
>         }
>     }
> }
> /**--------------code end----------**/
>
> According to JavaBeans Spec sec 8.8 "Capitalization of inferred names":
> Thus when we extract a property or event name from the middle of an
> existing Java name, we normally convert the first character to lower case.
> However to support the occasional use of all upper-case names, we check if
> the first two characters of the name are both upper case and if so leave it
> alone. So for example,
> “FooBah” becomes “fooBah”
> “Z” becomes “z”
> “URL” becomes “URL”
> We provide a method Introspector.decapitalize which implements this
> conversion rule.
> String java.beans.Introspector.decapitalize(String name)
> Utility method to take a string and convert it to normal Java variable
> name capitalization. This normally means converting the first character
> from upper case to lower case, but in the (unusual) special case when there
> is more than one character and both the first and second characters are
> upper case, we leave it alone.
> Thus "FooBah" becomes "fooBah" and "X" becomes "x", but "URL" stays as
> "URL".
>
>
>
>
>
> Best Regards
> Ma Liwei