Here are some more examples regarding the EL. If you don't know the Expression Language you may want to read this article by SUN.
Most of the EL-part should be implemented, some limitations are:
- floats are not parsed as decribed (floatval is used)
- scopes are partially implemented
- instanceof not implemented
- those "Implicit Objects" are not provided (param, requestScope, sessionScope and cookie is implemented for testing)
- properties are treated similiar to indices
If you know of more relevant differences, please let me know.
If you want, you could implement your own functions... more information and a list of currently implemented functions you could find at onjava.com
(To use those, you need to import logic_export)
c:set
var(default:temp), value(EL)
comparison
|
a: 20
b: 25
c: 32.5
a > b: false
c le b: false
c < b && a < c: false
|
{c:set var="a" value="20"/}
{c:set var="b" value="${a+5}"/}
{c:set var="c" value="${a+b/2}"/}
a: {c:out value="${a}"/}<br/>
b: {c:out value="${b}"/}<br/>
c: {c:out value="${c}"/}<br/>
a > b: {c:out value="${a > b}"/}<br/>
c le b: {c:out value="${c le b}"/}<br/>
c < b && a < c: {c:out value="${c < b && a < c}"/}<br/>
|
EL:empty
empty ...
|
s1: abc
s2:
s3:
empty s1: false
empty s2: true
empty s3: true
empty null: true
empty 'x': false
|
{c:set var="s1" value="abc"/}
{c:set var="s2" value=""/}
s1: {c:out value="${s1}"/}<br/>
s2: {c:out value="${s2}"/}<br/>
s3: {c:out value="${s3}"/}<br/>
empty s1: {c:out value="${empty s1}"/}<br/>
empty s2: {c:out value="${empty s2}"/}<br/>
empty s3: {c:out value="${empty s3}"/}<br/>
empty null: {c:out value="${empty null}"/}<br/>
empty 'x': {c:out value="${empty 'x'}"/}<br/>
|
fn:split
string, separator
fn:join
string, separator
|
0 |
item1 | 1 |
item2 | 2 |
item3 | 3 |
item4 | 4 |
item5 |
joined:item1 * item2 * item3 * item4 * item5
|
{c:set var="str1" value="item1,item2,item3,item4,item5"/}
{c:set var="list1" value="${fn:split(str1,',')}"/}
<table border="1">
<tr><th colspan="2">{c:out value="${str1}"/}</th></tr>
{c:forEach items="${list1}" var="item"}
<tr><td>{c:out value="${item.key}"/}</td>
<td>{c:out value="${item.value}"/}</td></tr>
{/c:forEach}
</table>
joined:{c:out value="${fn:join(list1,' * ')}"/}
|
c:if
test(EL)
|
0 |
item1 |
1 |
item2 |
2 |
item3 |
3 |
item4 |
4 |
item5 |
|
<table border="1">
<tr><th colspan="2">{c:out value="${str1}"/}</th></tr>
{c:forEach items="${list1}" var="item"}
{c:set var="style" value=""/}
{c:if test="${(item.key mod 2) == 0}"}
{c:set var="style" value="font-weight:bold;"/}
{/c:if}
<tr><td>{c:out value="${item.key}"/}</td>
<td style="{c:out value="${style}"/}">{c:out value="${item.value}"/}</td></tr>
{/c:forEach}
</table>
|
c:choose
c:when
test(EL)
c:otherwise
|
0 |
item1 |
1 |
item2 |
2 |
item3 |
3 |
item4 |
4 |
item5 |
|
<table border="1">
<tr><th colspan="2">{c:out value="${str1}"/}</th></tr>
{c:forEach items="${list1}" var="item"}
{c:choose}
{c:when test="${(item.key mod 3) == 0}"}
{c:set var="style" value="font-weight:bold;"/}
{/c:when}
{c:when test="${(item.key mod 3) == 1}"}
{c:set var="style" value="font-style:italic;"/}
{/c:when}
{c:otherwise}
{c:set var="style" value="text-decoration:underline;"/}
{/c:otherwise}
{/c:choose}
<tr><td>{c:out value="${item.key}"/}</td>
<td style="{c:out value="${style}"/}">{c:out value="${item.value}"/}</td></tr>
{/c:forEach}
</table>
|
|