EL访问器转换优先级

EL访问器转换优先级

本文介绍了获取时是否存在JSTL EL访问器转换优先级?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个由两部分组成的问题。



我有一个名为active的char属性的person对象。 Person有一个getActive()方法,它按预期返回一个char。在我的JSTL EL中,我有以下内容:

 < c:if test =$ {person.active ==' 1' }>有活性的LT; / C:如果> 

这绝不会过去。我的理解是JSTL中引用的文字是字符串(不管是单引号还是双引号),并且从getActive调用中保留了char类型,因此当getActive()返回字符'1'时,这两个值不相等。 / p>

作为替代方案,我添加了一个返回布尔值的isActive()方法。在这种情况下,以下工作:

 < c:if test =$ {person.active == true} >有活性的LT; / C:如果> 

以下是我的问题:


  1. 我对炭化比较的理解是否正确?如果是这样,有没有办法转换JSTL中的类型以使它们具有可比性?

  2. 当getActive()和isActive()都存在时,EL转换会调用哪一个?似乎isActive()获得优先权,但是有正式的文件订购吗?


解决方案

从第1.8章开始。 2 (强调我的):

char / 字符在EL中如此强制评估为。这永远不会等于'1'的字符串文字。






从第8.3.2节开始(强调我的):

这与强调点之后的点相结合以前引用的EL规范第1.8.2章,

将给出 isXxx()方法优先权。


This is sorta' a two-part question.

I have a person object with a char attribute on it called "active". Person has a getActive() method that returns a char as expected. In my JSTL EL, I have the following:

<c:if test="${person.active == '1'}">Active</c:if>

This never passes. My understanding is that quoted literals in JSTL are strings (regardless of single or double quote) and that the char type is being retained from the getActive call, so these two values are not equal when getActive() returns the character '1'.

As an alternative, I added an isActive() method which returns a boolean. In this case, the following works:

<c:if test="${person.active == true}">Active</c:if>

Here are my questions:

  1. Is my understanding correct regarding the char comparison? If so, is there any way to convert the types in JSTL so that they are comparable?
  2. When both getActive() and isActive() exist, which one gets called by the EL translation? It seems isActive() gets priority but is there an officially documented ordering to this?
解决方案

From chapter 1.8.2 of EL 2.2 specification (emphasis mine):

The char/Character is in EL thus coerced and evaluated as Long. That can never equal to a string literal of '1'.


From chapter 8.3.2 of Javabeans specification (emphasis mine):

This, in combination with the point right after the emphasized point in the previously quoted chapter 1.8.2 of EL spec,

will give the isXxx() method precedence.

这篇关于获取时是否存在JSTL EL访问器转换优先级?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 10:37