Is there a easy way to get complete info about JSTL and EL?

L

lightning

How do I get to know that :

<c:forEach var="cookieVal" items="${cookie}">
<c:if test="${cookieVal.key == 'abc'}">
<c:eek:ut value="${cookieVal.value.value}"></c:eek:ut>
</c:if>
</c:forEach>
only ${cookieVal.value.value} can output the right value of that
single cookie,but ${cookieVal.value} can not?
btw: it really sucks...


I saw some stuff on java.sun.com (http://java.sun.com/products/jsp/
syntax/2.0/syntaxref207.html#1010522)$B!$(Bbut it did not tell me the thing
above.

Must I search these tips on the planet or see the jsr???

I just need a manual,a chm for example,to deal with all the mess...
 
L

Lew

lightning said:
How do I get to know that :

<c:forEach var="cookieVal" items="${cookie}">
<c:if test="${cookieVal.key == 'abc'}">
<c:eek:ut value="${cookieVal.value.value}"></c:eek:ut>
</c:if>
</c:forEach>
only ${cookieVal.value.value} can output the right value of that
single cookie,but ${cookieVal.value} can not?
btw: it really sucks...


I saw some stuff on java.sun.com (http://java.sun.com/products/jsp/
syntax/2.0/syntaxref207.html#1010522),but it did not tell me the thing
above.

Must I search these tips on the planet or see the jsr???

I just need a manual,a chm for example,to deal with all the mess...

In general there isn't such a manual, although for JSTL generally the Sun
tutorial is a good start:
<http://java.sun.com/javaee/5/docs/tutorial/doc/bnakc.html>

The reason there isn't a general manual is that your problem depended on
specifics of your code, namely the types of 'cookieVal' and 'cookieVal.value'.
Apparently 'cookieVal.value' is itself of a holder type. What are those two
types?
 
L

lightning

  Apparently 'cookieVal.value' is itself of a holder type.  What are those two
types?

In fact, ${cookie} is provided by EL,not me, I've no idea what type it
is when I iterate the ${cookie}.
 
L

Lew

lightning said:
In fact, ${cookie} is provided by EL,not me, I've no idea what type it
is when I iterate the ${cookie}.

If you don't know the type of 'cookie', how do you know that you can iterate
through it?
 
L

Lew

Lew said:
If you don't know the type of 'cookie', how do you know that you can
iterate through it?

This is, of course, the heart of your problem.

As explained in
<http://www.informit.com/articles/article.aspx?p=30946&seqNum=7>
cookies is a Map. When you iterate over the Map, each iteration yields a
Map.Entry.

Your code extract (do NOT use TAB characters to indent Usenet listings):
<c:forEach var="cookieVal" items="${cookie}">
<c:if test="${cookieVal.key == 'abc'}">
<c:eek:ut value="${cookieVal.value.value}"></c:eek:ut>
</c:if>
</c:forEach>
only ${cookieVal.value.value} can output the right value of that
single cookie,but ${cookieVal.value} can not?
btw: it really sucks...

It sucks because you didn't check the data type first, so you failed to
understand what you needed to do.

The Entry has a value - that's ${cookieVal.value} - that's the Map.Entry value
right there. The value has a type - since ${cookies} is a Map from String to
javax.servlet.http.Cookie, that's the type of the value.
<http://java.sun.com/javaee/5/docs/api/javax/servlet/http/Cookie.html>
You want the value of the Cookie, which is the value of the value of the
Map.Entry:

${cookieVal.value.value}

Gee, that doesn't suck at all, not really, not in any way.

Q.E.D.
 
L

Lew

lightning said:
In fact, ${cookie} is provided by EL,not me, I've no idea what type it
is when I iterate the ${cookie}.

Incidentally, the point in asking you what the type was, since it was already
obvious that you didn't know, was to have you look it up, not just toss your
hands in the air and give up. It took me less than ten minutes of googling to
find the answer - you should have invested that time yourself. If you get in
the habit of finding out these answers, it'll become possible for you to write
code.
 
A

Arved Sandstrom

Lew said:
This is, of course, the heart of your problem.

As explained in
<http://www.informit.com/articles/article.aspx?p=30946&seqNum=7>
cookies is a Map. When you iterate over the Map, each iteration yields a
Map.Entry.

Your code extract (do NOT use TAB characters to indent Usenet listings):

It sucks because you didn't check the data type first, so you failed to
understand what you needed to do.

The Entry has a value - that's ${cookieVal.value} - that's the Map.Entry
value right there. The value has a type - since ${cookies} is a Map from
String to javax.servlet.http.Cookie, that's the type of the value.
<http://java.sun.com/javaee/5/docs/api/javax/servlet/http/Cookie.html>
You want the value of the Cookie, which is the value of the value of the
Map.Entry:

${cookieVal.value.value}

Gee, that doesn't suck at all, not really, not in any way.

Q.E.D.

Good explanation of those points. On a different note, why iterate over a
map if you are actually interested only in the value corresponding to one
key? A map implementation lets you test for the existence of a key. I am not
sure of the exact syntax here but I think it's something like

<c:if test="${not empty cookie["cookieName"]}">...

Don't hold me to it, but I think the above is close ('empty' apparently does
an empty test on collections but also does a null test). In any case, the
point is that it will be doable to test to see if the key ("abc") exists,
and then act on that, rather than iterate over all entries in the map.

AHS
 
L

Lew

Arved said:
Good explanation of those points. On a different note, why iterate over a
map if you are actually interested only in the value corresponding to one
key? A map implementation lets you test for the existence of a key. I am not
sure of the exact syntax here but I think it's something like

<c:if test="${not empty cookie["cookieName"]}">...

Don't hold me to it, but I think the above is close ('empty' apparently does
an empty test on collections but also does a null test). In any case, the

You're correct, and more than that, 'empty' subsumes the idiom for Strings
(x == null || x.length() == 0)

Basically, 'empty' matches the obvious interpretations of the word. It's as
if it had a series of reasonable tests for each valid expression type that it
can handle.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top