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?
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?
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}"/>
On JSF xhtml page, I use technics to reduce number of characters to type !
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:c="http://java.sun.com/jsp/jstl/core"
>
<!-- JSF ViewController of this page -->
<c:set var="vC" value="#{optionsViewController}"/>
...
<h:outputText
value="#{vC.txtOriginator.value}"
rendered="#{vC.txtOriginator.protected}"
/>
instead of
<h:outputText
value="#{optionsViewController.txtOriginator.value}"
rendered="#{optionsViewController.txtOriginator.protected}"
/>
Instead of typing optionsViewController
more than 100 types, I write define only vC
JSTL variable one time at begin of my xhtml file and use it each time I use optionsViewController
.
OTHER advantages:
The xhtml code is more short and more readable.
When I copy some lines of code using Paste/Copy between distinct
xhtml pages, vC
variable must not be replaced !
© 2022 - 2024 — McMap. All rights reserved.
${}
things as outlined in this JSP/EL spec: jsp.dev.java.net/spec/jsp-2_1-fr-spec-el.pdf – Janinajanine