struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joe Germuska <...@Germuska.com>
Subject Re: From bean into "for" loop
Date Mon, 24 May 2004 13:10:49 GMT
At 8:50 PM -0700 5/23/04, Andy Engle wrote:
>Hi all,
>
>I am trying to do something as simple as writing a FOR loop with some
>information that I have in a bean, but this is proving to be quite a
>bit more cumbersome and difficult than I thought it would be.  For some
>reason, everything I try seems to fail.  Here is a short example of
>what I'm trying to do:
>
><% for(int i = 0; i < ${productData.someCount}; i++) {  %>
>    // Write my text here
><% } %>
>
>What am I missing here?  If you could help me I'd appreciate it --
>enough time wasted on this thing already.

Is it that you are trying to use the JSTL-EL inside a scriptlet?  I 
don't think that works.  How about this:

<%

MyType productData = (MyType) request.getAttribute("productData");


for(int i = 0; i < productData.getSomeCount(); i++) {  %>
    // Write my text here
<% } %>

This also defines a page scoped variable named productData.  JSTL 
expressions go through a process of resolving names in several scopes 
but scriptlets don't; scriptlets only recognize variables which have 
been defined within their scope.

You're probably better off using the JSTL forEach tag, if you can 
expose a property on productData which returns an array, collection, 
or iterator.

Joe

-- 
Joe Germuska            
Joe@Germuska.com  
http://blog.germuska.com    
       "Imagine if every Thursday your shoes exploded if you tied them 
the usual way.  This happens to us all the time with computers, and 
nobody thinks of complaining."
             -- Jef Raskin

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message