commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 23558] - Problem with BeanUtils.setProperty when the name of property of Bean have on second caracter a uppercase
Date Sat, 10 Jan 2004 22:49:04 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=23558>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=23558

Problem with BeanUtils.setProperty when the name of property of Bean have on second caracter
a uppercase





------- Additional Comments From y.inoue@computer.org  2004-01-10 22:49 -------
The capitalization rule of PropertyDescriptor#getName() is as follows:

If the leading two characters following set(get) prefix are capitalized,
   the leading character of a property name is also capitalized.

Otherwise, the leading character of a property name is not capitalized.

examples:

set(get)AA --> AA (aA is expected)
set(get)NAmount --> NAmount (nAmount is expected)
set(get)Aa -> aa
set(get)VcName -> vcName

I don't know whether this rule is designated for acronyms or not. Method names
conforming to Java's naming rule would not encounter this bug. But, if database
people prefer to another naming rule that needs type prefix preceding nouns,
workarounds are required.

This is my workaround. See commented lines:

import java.beans.BeanInfo;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
public class TestCapitalization {

  private String aA;
  private String aa;
  private String nAmount;
  private String vcName;

  public String getAA() {return aA;}
  public String getAa() {return aa;}
  public String getNAmount() {return nAmount;}
  public String getVcName() {return vcName;}

  public void setAA(String aA) {this.aA = aA;}
  public void setAa(String aa) {this.aa = aa;}
  public void setNAmount(String nAmount) {this.nAmount = nAmount;}
  public void setVcName(String vcName) {this.vcName = vcName;}

  /*
  workaround: The leading character not to be capitalized.
  
  public String getaA() {getAA();}
  public void setaA(String aA) {setAA(aA);}
  */

  public static void main(String[] args) throws Exception {
      BeanInfo beanInfo = Introspector.getBeanInfo(TestCapitalization.class);
      PropertyDescriptor[] props = beanInfo.getPropertyDescriptors();
      for (int i=0; i < props.length; ++i) {
        System.out.println(props[i].getName());
      }
  }

}

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message