tags:

views:

1005

answers:

1

Whenever doing <c:set var="name" value="1" />, #{name} is always a String as evidenced by #{name.class}. Is there any way to in a JSF/Facelets context to set a scoped attribute that is an Integer or Long literal value?

+1  A: 

EL has Automatic Type Conversion. This article has some good information. However, the short of it is that you shouldn't care. You should be able to do things like the following as long as param.month is, in fact, an Integer.

<c:set var="myInteger" value="${param.month}"/>
<p>
The value of myInteger is:<c:out value="${myInteger}"/>
Perform a multiplication operation to show that the type is correct:
<c:out value="${myInteger *2}"/>
Randy Simon
+1 although I corrected that you incorrectly called it JSTL instead of EL. JSTL is a taglib as outlined here http://java.sun.com/products/jsp/jstl/1.1/docs/tlddocs/, EL are those `${}` things as outlined in this JSP/EL spec: https://jsp.dev.java.net/spec/jsp-2_1-fr-spec-el.pdf
BalusC
Ah, I just need to use an expression and not a literal, so if I do value="#{1}" then it will be a long. I still don't like how you can't control whether it is long or int though.
GreenieMeanie
Thanks, just a typo. My bad. I've been out of Java land for a while now.
Randy Simon
@GreenieMeanie: That's the nature of EL and usually shouldn't harm. If you want type safety, use JSF components instead. If it troubles, ask a new question how it hurts then we'll provide solutions/workarounds. By the way, using JSTL in JSF is not always considered a good practice.
BalusC
@Balus: The whole JSP/JSF/EL/JSTL/Facelets thing is a mess and so hard to keep track of the exact terms and versions these days...
GreenieMeanie
@GreenieMeanie: then you may find this answer useful: http://stackoverflow.com/questions/2095397/what-is-the-difference-between-jsf-servlet-and-jsp/2097732#2097732
BalusC