donderdag 18 februari 2010

JavaBean properties: uppercase vs lowercase

In general JavaBean properties can be accessed by the getter method without the get and the first letter in lowercase. For instance:

public class SomeClass {
  private String test;
  public String getTest(){return test;}
  public void setTest(String test){this.text=test;}
}

When accessing from the frontend this works fine:

#{someClass.text}

But when you have a property that begins with several capitals java doesn't find it when you only lowercase the first letter like this:

public class SomeClass {
  private String xml;
  public String getXML(){return xml;}
  public void setXML(String xml){this.xml=xml;}
}

someClass.xML and someClass.XML don't work. You need to lowercase all capitals in a row:

#{someClass.xml}

Some other examples:

getXMLData => xmldata
getXMLTestData => xmltestData
getXmlTestData => xmlTestData

Geen opmerkingen:

Een reactie plaatsen