Back Forum Reply New

modelandview items in jsp scriptlet

i can pass objects to view:

Code:
mav.addObject(quot;itemquot;, item);
and display data in jsp page:

Code:
${item.title} - ${item.pubdate}
but i have no idea how to access ${item} in jsp scriptlet, something like:

Code:
lt;%
if(last_date != ${item.pubdate}) out.write(${item.pubdate});
last_date = ${item.pubdate};
%gt;
what i'm acctualy trying to do is iterate through items list and check if previous item has different date than current.
i know i'm doing something wrong, any tips on how to do this?


Originally Posted by aljosa.mohorovici know i'm doing something wrong, any tips on how to do this?

can't you use core taglib?

products/jsp/jst...d-summary.html

Why not use the varStatus function on the JSTL lt;c:forEachgt; tag to get the previous item?

I'm going to assume that you have an java.util.Collection in your model called itemList.

So it would be something like:

Code:
lt;c:forEach items=quot;itemListquot; var=quot;itemquot; varStatus=quot;itemStatusquot;gt; lt;c:choosegt;   lt;%-- Item is not the first one and has the same date as the previous --%gt;   lt;c:when test=quot;${ not itemStatus.first and item.pubDate == itemList[itemStatus.index].pubDate }quot;gt;     lt;cut value=quot;${item.title} - same as previousquot;/gt;   lt;/c:whengt;   lt;%-- Item is either the first one or has a different date than previous --%gt;   lt;ctherwisegt;     lt;cut value=quot;${item.title} - ${item.pubdate}quot;/gt;   lt;/ctherwisegt; lt;/c:choosegt;
lt;/c:forEachgt;
NB: I haven't tested the above, so it might have bugs, but at least it gives the general idea.

Tony.

Do what Tony said and use the JSTL looping and conditional tags.

That said, the answer to your question is - any object pushed into the page model by Spring is accessible as an attribute of the PageContext, in request scope as follows: Code:
lt;%
System.out.println(pageContext.getAttribute(quot;itemquot;, PageContext.REQUEST_SCOPE));
%gt;thanks to all, i finally used jstl tags but now i understand better how to use them.
¥
Back Forum Reply New