0

We have a small application built using JSF 2.x. and Expression language with Tomcat 7 in Eclipse Luna.

In login.jsp,

 <jsp:include page="header.jsp"></jsp:include>

Inside header.jsp,

<c:choose>
<c:when test="${sessionScope.role eq 'B'}">
    <h:outputLink value="../../faces/pages/biller/Home.jsp">Home</h:outputLink>&nbsp;|&nbsp;
</c:when>
<c:when test="${sessionScope.role eq 'C'}">
<h:outputLink value="../../faces/pages/customer/Home.jsp">Home</h:outputLink>&nbsp;|&nbsp;
                        </c:when>
<c:otherwise>
        <h:outputLink value="../../faces/pages/login.jsp">Home</h:outputLink>&nbsp;|&nbsp;
                    </c:otherwise>
</c:choose>

In LoginBean, I have the instance variables as "role" of "String" type. I am using @SessionScoped and @ManagedBean annotations on LoginBean also.

When I try to log-in, it throws an Exception as -->

org.apache.jasper.JasperException: javax.el.ELException: Cannot convert B of type class java.lang.String to class java.lang.Long

I am not able to understand why "sessionScope.role" is giving a "Long" value.

If anyone has any idea, please help.

Edit:

On checking, I found it is giving me another exception like this:

javax.servlet.ServletException: /pages/SignUp.jsp(56,6) '#{registrationBean.userType eq 'C'}' Cannot convert C of type class java.lang.String to class java.lang.Long

although "userType" in Registration Bean is of type "Character"

Neither the # nor $ is working.

[![The following jars I have in lib folder][2]][2]

  1. antlr-2.7.7
  2. cglib-2.2
  3. commons-collections-3.1
  4. dom4j-1.6.1
  5. hibernate-commons-annotations-4.0.5.Final
  6. hibernate-core-4.3.9.Final
  7. hibernate-entitymanager-4.3.9.Final
  8. hibernate-jpa-2.1-api-1.0.0
  9. jandex-1.1.0.Final
  10. javaassist-3.18.1-GA
  11. javax.faces-2.2.10
  12. javax.persistence-2.1.0-RC2
  13. jboss-logging-3.1.3.GA
  14. jboss-transaction-api_1.2-spec-1.0.0.Final
  15. joda-time-2.2
  16. jstl
  17. jta-1.1
  18. junit-4.9b2
  19. log4j-1.2.15
  20. ojdbc7
  21. org.apache.commons.fileupload
  22. servlet-api
  23. servlet
  24. slf4j-api-1.6.1
  25. standard
A_J
  • 977
  • 4
  • 16
  • 44
  • @BalusC, apache-tomcat-7.0.52 – A_J Jul 26 '15 at 05:12
  • I have upgraded to Tomcat-7.0.63 but still the same issue – A_J Jul 26 '15 at 06:03
  • @BalusC I have updated the jar files I have in lib folder in Question. Should I include el.jar also. I am checking that link you have provided – A_J Jul 26 '15 at 06:31
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/84286/discussion-between-a-j-and-balusc). – A_J Jul 26 '15 at 06:38
  • what are container-specific jars ? Please tell what all jars should I include ? – A_J Jul 26 '15 at 06:41
  • Thanks @BalusC for your help. I will try to solve it now. – A_J Jul 26 '15 at 06:45

1 Answers1

0

The EL(expression language) works differently with combination of different JDKs/JREs and Tomcat versions.

With JDK 1.6 and some Tomcat-6 versions consider the following syntax as valid-->

<c:when test="${role eq 'B'}">    ---where 'role' is Character type in backing bean

Even JDK 1.7 with Tomcat 7.0.12 works fine for the above syntax.

But in JDK-8, most of the Tomcat versions (these have been tested-->6.0.44, 7.0.34, 7.0.52, 7.0.62, 7.0.63, 8.0.24) do not consider the above syntax as valid (because of the new EL2.2 specification). They would give an Exception like this -->

B of java.lang.String cannot be converted to java.lang.Long

This is because while parsing the above EL,

anything in quotes in EL is considered as String not character and is parsed as Long Unicode values.

So in order to make both as same we can write

<c:when test="${role eq 'B'.charAt(0)}">    

which is working fine even in earlier versions of JDKs and Tomcats.

Also to avoid these hassles of thinking which syntax to use where, we can do character comparisons in the backing bean and set a Boolean variable to true or false and then use this Boolean variable in jsp with rendered.

<c:if> not working for comparing characters
char comparison in EL expression

Community
  • 1
  • 1
A_J
  • 977
  • 4
  • 16
  • 44