You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by Vernon Wu <ve...@gatewaytech.com> on 2002/09/11 01:56:41 UTC
How to access an element of array without using the iteration tag
I need to access the first element of array using JSTL. After a few of trial and error, I don't success without using the
iteration tag. I don't image that is a difficult one, but just don't know how.
Thanks for your cue.
Vernon
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: How to access an element of array without using the iteration tag
Posted by "David M. Karr" <dm...@earthlink.net>.
>>>>> "Vernon" == Vernon Wu <ve...@gatewaytech.com> writes:
Vernon> Thanks Hans for your quick response.
Vernon> 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
Vernon> have to use the script as the followings:
Vernon> <% if(prov.getPhotoPaths() == null) { %>
Vernon> <IMG SRC="<%=request.getContextPath()%>/images/no_photo.gif" NAME="No Photo Available"
Vernon> ALIGN=BOTTOM BORDER=0>
Vernon> <% } else { %>
Vernon> <IMG SRC="<%=(prov.getPhotoPaths())[0]%>" NAME="Photo" ALIGN=BOTTOM BORDER=0>
Vernon> <% } %>
Vernon> <IMG SRC="${prov.photoPaths[0]}"> doesn't seem to work.
Then i would guess you actually want this:
<IMG SRC='<c:out value="${prov.photoPaths[0]}"/>'>
However, this will only work if you created a scoped variable named "prov" from
the "prov" variable. You don't show that happening here. Scoped variables are
not the same as scripting variables. A scoped variable is just a page,
request, session, or application attribute.
--
===================================================================
David M. Karr ; Java/J2EE/XML/Unix/C++
dmkarr@earthlink.net
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: How to access an element of array without using the iteration tag
Posted by Vernon Wu <ve...@gatewaytech.com>.
I almost simultaneously received all your three's reply. Thanks your all. I shall remember that EL only validates inside of
the tag space.
Good night.
9/10/2002 6:12:21 PM, Hans Bergsten <ha...@gefionsoftware.com> wrote:
>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: <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: How to access an element of array without using the iteration
tag
Posted by Hans Bergsten <ha...@gefionsoftware.com>.
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: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: How to access an element of array without using the iteration tag
Posted by Vernon Wu <ve...@gatewaytech.com>.
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.
9/10/2002 5:01:53 PM, Hans Bergsten <ha...@gefionsoftware.com> wrote:
>Vernon Wu wrote:
>> I need to access the first element of array using JSTL. After a few of trial and error, I don't success without using the
>> iteration tag. I don't image that is a difficult one, but just don't know how.
>>
>> Thanks for your cue.
>
>Use an EL expression like this: ${myArray[0]}
>
>Hans
>--
>Hans Bergsten hans@gefionsoftware.com
>Gefion Software http://www.gefionsoftware.com
>JavaServer Pages http://TheJSPBook.com
>
>
>--
>To unsubscribe, e-mail: <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: How to access an element of array without using the iteration
tag
Posted by Hans Bergsten <ha...@gefionsoftware.com>.
Vernon Wu wrote:
> I need to access the first element of array using JSTL. After a few of trial and error, I don't success without using the
> iteration tag. I don't image that is a difficult one, but just don't know how.
>
> Thanks for your cue.
Use an EL expression like this: ${myArray[0]}
Hans
--
Hans Bergsten hans@gefionsoftware.com
Gefion Software http://www.gefionsoftware.com
JavaServer Pages http://TheJSPBook.com
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>