4

I have this unusual scenario:

I have a registrationVO with few properties and getter setters for that. For example city or bCity with their getter methods getCity() and getBCity()

In JSP i tried to display the value of these properties using scriplets, <%=registrationVO.getCity()%> and <%=registrationVO.getBCity()%> , It works fine. But i replaced the same with expression language, ${registrationVO.city} and ${registrationVO.bCity} i got an error saying property "bCity" not found in registrationVO. i a used scriplet again for bCity, i got the output.

I observed that its because of the naming convention. "If the second character of the property is a Capital letter we cant use Expression Language". I have tried with many diff namings, this is what i found out.

Please check this scenario, I don't know wether my conclusion is right or wrong.

Thanks, DJ

1 Answer 1

9

If the property name of the getter method starts with at least two uppercase characters, then you need to use all of those uppercase characters in the EL property name as well. In your particular case, you need to replace it by ${registrationVO.BCity}. This is specified in chapter 8.8 of the Javabeans spec. Here's an extract of the chapter (emphasis mine):

8.8 Capitalization of inferred names.

When we use design patterns to infer a property or event name, we need to decide what rules to follow for capitalizing the inferred name. If we extract the name from the middle of a normal mixedCase style Java name then the name will, by default, begin with a capital letter.

Java programmers are accustomed to having normal identifiers start with lower case letters. Vigorous reviewer input has convinced us that we should follow this same conventional rule for property and event 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.

That said, I would rather rename them to something more sensible. Maybe birthCity (if I guess it right), so that you can just nicely use ${registrationVO.birthCity}.

Sign up to request clarification or add additional context in comments.

3 Comments

Hi Balus, Thanks for ypur reply. It really helped me as it worked. but il take your suggestion and rename it as billing City and billingState. Thanks, DJ
this information (about the two uppercase chars), it is true indeed. But how can I reference it to someone to prove that fact without actually showing it working? It is written in some documentation, or only in the EL code itself?
@bluefoot: Truly, it's specified in chapter 8.8 of Javabeans spec. I edited the answer to include a cite.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.