Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2008

Tip: Looking for answers? Try searching our database.

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

Thread view: 
lightning - 14 Mar 2008 07:50 GMT
How do I get to know that :

    <c:forEach var="cookieVal" items="${cookie}">
        <c:if test="${cookieVal.key == 'abc'}">
            <c:out value="${cookieVal.value.value}"></c:out>
        </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...
Lew - 14 Mar 2008 13:46 GMT
> How do I get to know that :
>
[quoted text clipped - 14 lines]
>
> 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?

Signature

Lew

lightning - 17 Mar 2008 05:56 GMT
>   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}.
Lew - 17 Mar 2008 07:58 GMT
>>   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}.

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

Signature

Lew

Lew - 17 Mar 2008 08:08 GMT
>>>   Apparently 'cookieVal.value' is itself of a holder type.  What are
>>> those two
[quoted text clipped - 5 lines]
> 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'}">
[quoted text clipped - 4 lines]
> 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.

Signature

Lew

Arved Sandstrom - 17 Mar 2008 16:21 GMT
>>>>   Apparently 'cookieVal.value' is itself of a holder type.  What are
>>>> those two
[quoted text clipped - 38 lines]
>
> 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
Lew - 18 Mar 2008 02:32 GMT
> 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
[quoted text clipped - 5 lines]
> 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.

> 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.

Signature

Lew

Lew - 17 Mar 2008 08:15 GMT
>>   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}.

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.

Signature

Lew



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.