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:
- 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?
- 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/Characteris in EL thus coerced and evaluated asLong. 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.