tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hans Bergsten <h...@gefionsoftware.com>
Subject Re: How to access an element of array without using the iteration tag
Date Wed, 11 Sep 2002 01:12:21 GMT
Vernon Wu wrote:
> Thanks Hans for your quick response. 
> 
> In fact, I didn't phrase my question right. The data is a path of an image. The expression
doesn't work in the situation. I 
> have to use the script as the followings:
> 
> 	<% if(prov.getPhotoPaths() == null) { %>
> 		<IMG SRC="<%=request.getContextPath()%>/images/no_photo.gif" NAME="No Photo
Available" 
> ALIGN=BOTTOM BORDER=0>
>       	<% } else {  %> 
>       		<IMG SRC="<%=(prov.getPhotoPaths())[0]%>" NAME="Photo" ALIGN=BOTTOM
BORDER=0>
>       	<% } %>
> 
> <IMG SRC="${prov.photoPaths[0]}"> doesn't seem to work.

That's because you're using Java code in scriptlets, not JSTL and the EL
as you asked about. With JSTL and EL, something like this should work:

   <c:choose>
     <c:when test="${empty prov.photoPaths}">
       <IMG SRC="<c:url value="/images/no_photo.gif" />"
         NAME="No Photo Available" ALIGN=BOTTOM BORDER=0>
     </c:when>
     <c:otherwise>
       <IMG SRC="<c:out value="${prov.photoPaths[0]}" />"
         NAME="Photo" ALIGN=BOTTOM BORDER=0>
     </c:otherwise>
   </c:choose>

Note the use of <c:url> for the case when no path is provided; it adds
the context path automatically for you.

Hans
-- 
Hans Bergsten		hans@gefionsoftware.com
Gefion Software		http://www.gefionsoftware.com
JavaServer Pages	http://TheJSPBook.com


--
To unsubscribe, e-mail:   <mailto:taglibs-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:taglibs-user-help@jakarta.apache.org>


Mime
View raw message