属性名称的第二个字符为大写字母时,javax.el.PropertyNotFoundException [英] javax.el.PropertyNotFoundException when second character of property name is a capital

查看:90
本文介绍了属性名称的第二个字符为大写字母时,javax.el.PropertyNotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个不寻常的情况:

I have this unusual scenario:

我有一个RegistrationVO,它几乎没有属性和获取方法。
,例如 city bCity 的getter方法 getCity() getBCity()

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

在JSP中,我尝试使用scriplets显示这些属性的值,
<%= registrationVO.getCity()%> 和< %= registrationVO.getBCity()%> ,效果很好。
但是我用表达式语言替换了它们,
$ {registrationVO.city} $ {registrationVO.bCity}
i出现错误,指出在registrationVO中找不到属性 bCity。
再次成为bCity的二手电子书,我得到了输出。

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.

谢谢,
DJ

Thanks, DJ

推荐答案

如果getter方法至少以两个大写字符开头,然后还需要在EL属性名称中使用所有这些大写字符。在您的特定情况下,您需要用 $ {registrationVO.BCity} 替换它。在 Javabeans规范的第8.8章中对此进行了指定。这是本章的重点(强调我的意思):

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推断名称的大写。


当我们使用设计时模式以推断属性或事件名称,我们需要确定遵循
的规则以大写推断名称。如果我们从普通的
混合大小写样式Java名称的中间提取名称,则该名称默认情况下以大写字母开头。

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程序员习惯于使用普通标识符以小写字母开头。
强有力的审阅者的意见使我们确信,对于属性和事件名称,我们应该遵循相同的常规规则

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.

因此,当我们从列表中提取属性或事件名称时在现有Java名称的中间,我们
通常会将第一个字符转换为小写。 不过,为了支持偶尔使用所有
大写名称,我们会检查名称的前两个字符是否均为大写,以及
是否保留为空
。因此,例如,

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变成 fooBah

  • Z变成 z

  • URL变为 URL

我们提供了一种方法 Introspector.decapitalize

We provide a method Introspector.decapitalize which implements this conversion rule.

也就是说,我宁愿将它们重命名为更明智的名称。也许 birthCity (如果我猜对了),这样您就可以很好地使用 $ {registrationVO.birthCity}

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}.

这篇关于属性名称的第二个字符为大写字母时,javax.el.PropertyNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆