You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Tony Smith <qu...@yahoo.com> on 2005/07/02 17:56:40 UTC

Iterate without collection

If I just want to go through a loop and print out 1,
2, ...10, how can I do it with <logic:iterate>? Here
is my jsp:

<logic:iterate id="index" indexId="number"
length="10">
$<number>
</logic:iterate>

It complained that  "Null attribute name". 

THanks,




		
__________________________________ 
Discover Yahoo! 
Stay in touch with email, IM, photo sharing and more. Check it out! 
http://discover.yahoo.com/stayintouch.html

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


Re: Iterate without collection

Posted by Martin Gainty <mg...@hotmail.com>.
this example from Kumar at JGuru:

//this takes the contents of ArrayListName and assigns an iterator
<logic:iterate id="tempOject" name="ArrayListName" property="fieldobj">

//write out the contents of iterator id based on keyvalue supplied at 
property
<bean:write name="tempOject" property="KeyValue" />

Be mindful that Currently, this tag cannot deal with arrays of primitive 
data types. Only arrays of Java objects (including Strings) are supported.
Also To populate the ArrayListName in your jsp
Set the String value stored in action and retrieve here in jsp page through 
this way . This stores the objectOfArayList inside to ArrayListName
request.setAttribute("ArrayListName", objectOfArayList);
I encourage you ro read the logic: tag information available at
http://www.jajakarta.org/struts/struts1.0/en/target/documentation/struts-logic.html

HTH
Martin-
            Is

----- Original Message ----- 
From: "Wendy Smoak" <ja...@wendysmoak.com>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Sunday, July 03, 2005 7:53 AM
Subject: Re: Iterate without collection


> From: "Tony Smith" <qu...@yahoo.com>
>
>>I am using jsp to print out a table. The data (dxx)
>> comes from a formbean. At the beginning of every row,
>> I would like to print a character starting from 'A'.
>>
>> A  d11 d12 d13...
>> B  d21 d22 d23...
>> C  d31 d32 d33...
>
> If you put the rows into a TreeMap and use A,B,C... for the keys, then 
> they will come out in the correct order when you feed the Map to 
> <logic:iterate>.
>
> But... your subject line says "without collection" so I'm still not sure 
> what you need here.  If you show the form bean property that goes with 
> this table, and a snippet of JSP where you're trying to do the iteration, 
> it might make more sense to me.
>
> In another message you asked how to convert 0 to A, 1 to B, etc.  If you 
> add 65 to the int and cast it to char, you'll get the right letter.
>
> -- 
> Wendy Smoak
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
> 

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


Re: Iterate without collection

Posted by Wendy Smoak <ja...@wendysmoak.com>.
From: "Tony Smith" <qu...@yahoo.com>
>
> How can I cast int to char in jsp?
>

I'm more than willing to help, but I really need to see what you're working 
with.  At the very least I want to know what the form property that's behind 
this table looks like.  What type is it?  (And can you change it, or add 
another method to the form?)  A snippet from the JSP where you're trying to 
do the iteration would also be helpful.

As far as casting, I was just playing around with it in a scriptlet.  It 
works the same way it would in a regular Java class.  An interesting 
diversion (I had to go look up the ASCII value of 'A') but I'm not sure it's 
going to factor in the actual solution here.

-- 
Wendy Smoak
 



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


Re: Iterate without collection

Posted by Tony Smith <qu...@yahoo.com>.
That is cool. But is this going to work:

<table>
<logic:iterate id="cell" indexId = "idx" name="myform"
propert="myListInForm">
<tr>
 <td><%= Character.toString (idx + 65) %></td>
 <td>${id}</td>
</logic:iterate>
</tr>
</table>

Suppose I have a list in my form with data "d1", "d2",
"d3"...

I want to print out:

A d1
B d2
C d3
...


--- Thomas Corte <Th...@knipp.de> wrote:

> Hi,
> 
> Tony Smith wrote:
> 
> > How can I cast int to char in jsp?
> 
> Try
> 
>    <%= Character.toString (i + 65) %>
> 
> -- 
> Thomas Corte
> Thomas.Corte@knipp.de
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> user-unsubscribe@struts.apache.org
> For additional commands, e-mail:
> user-help@struts.apache.org
> 
> 



		
____________________________________________________ 
Yahoo! Sports 
Rekindle the Rivalries. Sign up for Fantasy Football 
http://football.fantasysports.yahoo.com

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


Re: Iterate without collection

Posted by Thomas Corte <Th...@knipp.de>.
Hi,

Tony Smith wrote:

> How can I cast int to char in jsp?

Try

   <%= Character.toString (i + 65) %>

-- 
Thomas Corte
Thomas.Corte@knipp.de

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


Re: Iterate without collection

Posted by Tony Smith <qu...@yahoo.com>.
How can I cast int to char in jsp?

Thanks,

--- Wendy Smoak <ja...@wendysmoak.com> wrote:

> From: "Tony Smith" <qu...@yahoo.com>
> 
> >I am using jsp to print out a table. The data (dxx)
> > comes from a formbean. At the beginning of every
> row,
> > I would like to print a character starting from
> 'A'.
> >
> > A  d11 d12 d13...
> > B  d21 d22 d23...
> > C  d31 d32 d33...
> 
> If you put the rows into a TreeMap and use A,B,C...
> for the keys, then they 
> will come out in the correct order when you feed the
> Map to <logic:iterate>.
> 
> But... your subject line says "without collection"
> so I'm still not sure 
> what you need here.  If you show the form bean
> property that goes with this 
> table, and a snippet of JSP where you're trying to
> do the iteration, it 
> might make more sense to me.
> 
> In another message you asked how to convert 0 to A,
> 1 to B, etc.  If you add 
> 65 to the int and cast it to char, you'll get the
> right letter.
> 
> -- 
> Wendy Smoak 
> 
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> user-unsubscribe@struts.apache.org
> For additional commands, e-mail:
> user-help@struts.apache.org
> 
> 



		
____________________________________________________ 
Yahoo! Sports 
Rekindle the Rivalries. Sign up for Fantasy Football 
http://football.fantasysports.yahoo.com

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


Re: Iterate without collection

Posted by Wendy Smoak <ja...@wendysmoak.com>.
From: "Tony Smith" <qu...@yahoo.com>

>I am using jsp to print out a table. The data (dxx)
> comes from a formbean. At the beginning of every row,
> I would like to print a character starting from 'A'.
>
> A  d11 d12 d13...
> B  d21 d22 d23...
> C  d31 d32 d33...

If you put the rows into a TreeMap and use A,B,C... for the keys, then they 
will come out in the correct order when you feed the Map to <logic:iterate>.

But... your subject line says "without collection" so I'm still not sure 
what you need here.  If you show the form bean property that goes with this 
table, and a snippet of JSP where you're trying to do the iteration, it 
might make more sense to me.

In another message you asked how to convert 0 to A, 1 to B, etc.  If you add 
65 to the int and cast it to char, you'll get the right letter.

-- 
Wendy Smoak 



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


Re: Iterate without collection

Posted by Tony Smith <qu...@yahoo.com>.
I am using jsp to print out a table. The data (dxx)
comes from a formbean. At the beginning of every row,
I would like to print a character starting from 'A'. 

Some my table looks like


A  d11 d12 d13...
B  d21 d22 d23...
C  d31 d32 d33...

--- Wendy Smoak <ja...@wendysmoak.com> wrote:

> From: "Tony Smith" <qu...@yahoo.com>
> >
> > can I do it with <logic:iterate>?
> >
> > In jsp, with struts tag library, how can I change
> 0 to
> > 'A', 1 to 'B', ...
> >
> 
> As far as I can tell from the docs... not without
> putting the things you 
> want to display into a Collection.
> 
> How about describing the problem you're trying to
> solve, instead of the one 
> solution that you're trying to get working?  It's
> quite possible that 
> someone can suggest a better solution that works
> within your constraints.
> 
> (Without knowing anything else about your project,
> I'd say just stick a 
> scriptlet in the JSP to populate an ArrayList, put
> that in page scope, and 
> then use <logic:iterate> on it.)
> 
> Meanwhile... JSTL can do this...
> 
>    <c:forTokens items="A,B,C,D,E" delims=","
> var="token">
>        <c:out value="${token}"/>
>    </c:forTokens>
> 
> -- 
> Wendy Smoak 
> 
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> user-unsubscribe@struts.apache.org
> For additional commands, e-mail:
> user-help@struts.apache.org
> 
> 



		
__________________________________ 
Discover Yahoo! 
Stay in touch with email, IM, photo sharing and more. Check it out! 
http://discover.yahoo.com/stayintouch.html

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


Re: Iterate without collection

Posted by Wendy Smoak <ja...@wendysmoak.com>.
From: "Tony Smith" <qu...@yahoo.com>
>
> can I do it with <logic:iterate>?
>
> In jsp, with struts tag library, how can I change 0 to
> 'A', 1 to 'B', ...
>

As far as I can tell from the docs... not without putting the things you 
want to display into a Collection.

How about describing the problem you're trying to solve, instead of the one 
solution that you're trying to get working?  It's quite possible that 
someone can suggest a better solution that works within your constraints.

(Without knowing anything else about your project, I'd say just stick a 
scriptlet in the JSP to populate an ArrayList, put that in page scope, and 
then use <logic:iterate> on it.)

Meanwhile... JSTL can do this...

   <c:forTokens items="A,B,C,D,E" delims="," var="token">
       <c:out value="${token}"/>
   </c:forTokens>

-- 
Wendy Smoak 



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


Re: Iterate without collection

Posted by Tony Smith <qu...@yahoo.com>.
In jsp, with struts tag library, how can I change 0 to
'A', 1 to 'B', ...

Thanks,


--- Tony Smith <qu...@yahoo.com> wrote:

> can I do it with <logic:iterate>?
> 
> 
> --- Wendy Smoak <ja...@wendysmoak.com> wrote:
> 
> > From: "Tony Smith" <qu...@yahoo.com>
> > > If I just want to go through a loop and print
> out
> > 1,
> > > 2, ...10, how can I do it with <logic:iterate>?
> > 
> > Here's a gentle shove in the JSTL direction...
> > http://struts.apache.org/userGuide/dev_logic.html
> > 
> > <%@ taglib uri="http://java.sun.com/jstl/core" 
> > prefix="c" %>
> > <c:forEach begin="0" end="10" var="num">
> >    <c:out value="${num}" />
> > </c:forEach>
> > 
> > (If you're on a JSP 2.0 container, you can drop
> the
> > <c:out> and use the 
> > expression directly.)
> > 
> > -- 
> > Wendy Smoak 
> > 
> > 
> > 
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> > user-unsubscribe@struts.apache.org
> > For additional commands, e-mail:
> > user-help@struts.apache.org
> > 
> > 
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam
> protection around 
> http://mail.yahoo.com 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> user-unsubscribe@struts.apache.org
> For additional commands, e-mail:
> user-help@struts.apache.org
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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


Re: Iterate without collection

Posted by Tony Smith <qu...@yahoo.com>.
can I do it with <logic:iterate>?


--- Wendy Smoak <ja...@wendysmoak.com> wrote:

> From: "Tony Smith" <qu...@yahoo.com>
> > If I just want to go through a loop and print out
> 1,
> > 2, ...10, how can I do it with <logic:iterate>?
> 
> Here's a gentle shove in the JSTL direction...
> http://struts.apache.org/userGuide/dev_logic.html
> 
> <%@ taglib uri="http://java.sun.com/jstl/core" 
> prefix="c" %>
> <c:forEach begin="0" end="10" var="num">
>    <c:out value="${num}" />
> </c:forEach>
> 
> (If you're on a JSP 2.0 container, you can drop the
> <c:out> and use the 
> expression directly.)
> 
> -- 
> Wendy Smoak 
> 
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> user-unsubscribe@struts.apache.org
> For additional commands, e-mail:
> user-help@struts.apache.org
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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


Re: Iterate without collection

Posted by Wendy Smoak <ja...@wendysmoak.com>.
From: "Tony Smith" <qu...@yahoo.com>
> If I just want to go through a loop and print out 1,
> 2, ...10, how can I do it with <logic:iterate>?

Here's a gentle shove in the JSTL direction...
http://struts.apache.org/userGuide/dev_logic.html

<%@ taglib uri="http://java.sun.com/jstl/core"  prefix="c" %>
<c:forEach begin="0" end="10" var="num">
   <c:out value="${num}" />
</c:forEach>

(If you're on a JSP 2.0 container, you can drop the <c:out> and use the 
expression directly.)

-- 
Wendy Smoak 



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