You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Milan Milanovic <mi...@yahoo.com> on 2008/05/30 15:58:24 UTC

[Struts 2] How to iterate to simple value ?

Hi,

I have one int (myInt) in my action class, and I want to iterate in my jsp from 0 to that int (myInt), how can I do this ?

I tried like this:

<s:iterator value="myInt" status="iterstatus">
        <s:url id="url" action="list.action">
            <s:param name="myInt"><s:property/></s:param>
        </s:url>
        <s:a href="%{url}"><s:property/></s:a>
</s:iterator>

But it only writes its value, it doesn't iterate at all.

--
Thx, Milan

       

Re: [Struts 2] How to iterate to simple value ?

Posted by Martin <mg...@hotmail.com>.
yep..it was in the doc..
http://struts.apache.org/2.x/docs/iterator-tag-examples.html
the tricky part is determining whats at the top of the stack (LIFO...?)
<s:iterator value="countries">
    <s:iterator value="cities">
        <s:property value="name"/>, <s:property value="[1].name"/><br>
    </s:iterator>
</s:iterator>

.since the last object is city
Dublin, Ireland
Cork, Ireland

Berlin, Germany
Heidelberg, Germany

Stockholm, Sweden
Lund, Sweden

HTH
Martin
----- Original Message ----- 
From: "Jim Kiley" <jh...@summa-tech.com>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Friday, May 30, 2008 10:19 AM
Subject: Re: [Struts 2] How to iterate to simple value ?


> Yes, that is the example I was referring to.  To use it, you will have to
> figure out how to create an integer array of the values 1.. your integer.
> I'm willing to bet that you can do that.  Alternatively you may be able to
> figure out another way to solve the problem.
>
> jk
>
> On Fri, May 30, 2008 at 10:16 AM, Milan Milanovic 
> <mi...@yahoo.com>
> wrote:
>
>> Do you mean this example:
>>
>> o simulate a simple loop with iterator tag, the following could be done. 
>> It
>> does the loop 5 times.
>> <s:iterator status="stat" value="{1,2,3,4,5}" >
>>   <!-- grab the index (start with 0 ... ) -->
>>   <s:property value="#stat.index" />
>>
>>   <!-- grab the top of the stack which should be the -->
>>   <!-- current iteration value (0, 1, ... 5) -->
>>   <s:property value="top" />
>> </s:iterator>
>>
>> ?
>>
>> But this iterator uses an array ?
>>
>> --
>> Thx, Milan
>>
>>
>>
>>
>>
>> Jim Kiley <jh...@summa-tech.com> wrote: Read the example at the bottom
>> of the URL I provided.  That is one
>> solution.  You may be able to come up with your own.  I encourage you to 
>> do
>> so if you are dissatisfied with that example.
>>
>> On Fri, May 30, 2008 at 10:08 AM, Milan Milanovic
>> wrote:
>>
>> > O.K.
>> >
>> > But is there any solution to this, besides putting that value into an
>> array
>> > ?
>> >
>> > --
>> > Thx, Milan
>> >
>> > Jim Kiley  wrote: You can only iterate over an
>> > array or a Collection -- something that has an
>> > iterator() method.  Integers (and particularly ints) don't.  If you had
>> > looked up the iterator tag at
>> > http://cwiki.apache.org/WW/iterator.htmlbefore mailing the list, you
>> > would have seen at the bottom of the page an
>> > example of emulating a simple counter loop.
>> >
>> > That same page indicates that if you provide just a single non-iterable
>> > value, it will be placed into a List, which is subsequently iterated
>> over.
>> > That is why you are seeing just your one value once.
>> >
>> > jk
>> >
>> > On Fri, May 30, 2008 at 9:58 AM, Milan Milanovic
>> > wrote:
>> >
>> > > Hi,
>> > >
>> > > I have one int (myInt) in my action class, and I want to iterate in 
>> > > my
>> > jsp
>> > > from 0 to that int (myInt), how can I do this ?
>> > >
>> > > I tried like this:
>> > >
>> > >
>> > >
>> > >
>> > >
>> > >
>> > >
>> > >
>> > > But it only writes its value, it doesn't iterate at all.
>> > >
>> > > --
>> > > Thx, Milan
>> > >
>> > >
>> >
>> >
>> >
>> >
>> > --
>> > Jim Kiley
>> > Technical Consultant | Summa
>> > [p] 412.258.3346 [m] 412.445.1729
>> > http://www.summa-tech.com
>> >
>> >
>> >
>> >
>>
>>
>>
>> --
>> Jim Kiley
>> Technical Consultant | Summa
>> [p] 412.258.3346 [m] 412.445.1729
>> http://www.summa-tech.com
>>
>>
>>
>>
>
>
>
> -- 
> Jim Kiley
> Technical Consultant | Summa
> [p] 412.258.3346 [m] 412.445.1729
> http://www.summa-tech.com
> 


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


Re: [Struts 2] How to iterate to simple value ?

Posted by Milan Milanovic <mi...@yahoo.com>.
Oh, yes, in my getMyInt() method I can create temporary array from 0 to myInt.

Sorry and thanks.

--
Milan

Jim Kiley <jh...@summa-tech.com> wrote: Yes, that is the example I was referring to.  To use it, you will have to
figure out how to create an integer array of the values 1.. your integer.
I'm willing to bet that you can do that.  Alternatively you may be able to
figure out another way to solve the problem.

jk

On Fri, May 30, 2008 at 10:16 AM, Milan Milanovic 
wrote:

> Do you mean this example:
>
> o simulate a simple loop with iterator tag, the following could be done. It
> does the loop 5 times.
> 
>   
>   
>
>   
>   
>   
> 
>
> ?
>
> But this iterator uses an array ?
>
> --
> Thx, Milan
>
>
>
>
>
> Jim Kiley  wrote: Read the example at the bottom
> of the URL I provided.  That is one
> solution.  You may be able to come up with your own.  I encourage you to do
> so if you are dissatisfied with that example.
>
> On Fri, May 30, 2008 at 10:08 AM, Milan Milanovic
> wrote:
>
> > O.K.
> >
> > But is there any solution to this, besides putting that value into an
> array
> > ?
> >
> > --
> > Thx, Milan
> >
> > Jim Kiley  wrote: You can only iterate over an
> > array or a Collection -- something that has an
> > iterator() method.  Integers (and particularly ints) don't.  If you had
> > looked up the iterator tag at
> > http://cwiki.apache.org/WW/iterator.htmlbefore mailing the list, you
> > would have seen at the bottom of the page an
> > example of emulating a simple counter loop.
> >
> > That same page indicates that if you provide just a single non-iterable
> > value, it will be placed into a List, which is subsequently iterated
> over.
> > That is why you are seeing just your one value once.
> >
> > jk
> >
> > On Fri, May 30, 2008 at 9:58 AM, Milan Milanovic
> > wrote:
> >
> > > Hi,
> > >
> > > I have one int (myInt) in my action class, and I want to iterate in my
> > jsp
> > > from 0 to that int (myInt), how can I do this ?
> > >
> > > I tried like this:
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > But it only writes its value, it doesn't iterate at all.
> > >
> > > --
> > > Thx, Milan
> > >
> > >
> >
> >
> >
> >
> > --
> > Jim Kiley
> > Technical Consultant | Summa
> > [p] 412.258.3346 [m] 412.445.1729
> > http://www.summa-tech.com
> >
> >
> >
> >
>
>
>
> --
> Jim Kiley
> Technical Consultant | Summa
> [p] 412.258.3346 [m] 412.445.1729
> http://www.summa-tech.com
>
>
>
>



-- 
Jim Kiley
Technical Consultant | Summa
[p] 412.258.3346 [m] 412.445.1729
http://www.summa-tech.com


       

Re: [Struts 2] How to iterate to simple value ?

Posted by Jim Kiley <jh...@summa-tech.com>.
Yes, that is the example I was referring to.  To use it, you will have to
figure out how to create an integer array of the values 1.. your integer.
I'm willing to bet that you can do that.  Alternatively you may be able to
figure out another way to solve the problem.

jk

On Fri, May 30, 2008 at 10:16 AM, Milan Milanovic <mi...@yahoo.com>
wrote:

> Do you mean this example:
>
> o simulate a simple loop with iterator tag, the following could be done. It
> does the loop 5 times.
> <s:iterator status="stat" value="{1,2,3,4,5}" >
>   <!-- grab the index (start with 0 ... ) -->
>   <s:property value="#stat.index" />
>
>   <!-- grab the top of the stack which should be the -->
>   <!-- current iteration value (0, 1, ... 5) -->
>   <s:property value="top" />
> </s:iterator>
>
> ?
>
> But this iterator uses an array ?
>
> --
> Thx, Milan
>
>
>
>
>
> Jim Kiley <jh...@summa-tech.com> wrote: Read the example at the bottom
> of the URL I provided.  That is one
> solution.  You may be able to come up with your own.  I encourage you to do
> so if you are dissatisfied with that example.
>
> On Fri, May 30, 2008 at 10:08 AM, Milan Milanovic
> wrote:
>
> > O.K.
> >
> > But is there any solution to this, besides putting that value into an
> array
> > ?
> >
> > --
> > Thx, Milan
> >
> > Jim Kiley  wrote: You can only iterate over an
> > array or a Collection -- something that has an
> > iterator() method.  Integers (and particularly ints) don't.  If you had
> > looked up the iterator tag at
> > http://cwiki.apache.org/WW/iterator.htmlbefore mailing the list, you
> > would have seen at the bottom of the page an
> > example of emulating a simple counter loop.
> >
> > That same page indicates that if you provide just a single non-iterable
> > value, it will be placed into a List, which is subsequently iterated
> over.
> > That is why you are seeing just your one value once.
> >
> > jk
> >
> > On Fri, May 30, 2008 at 9:58 AM, Milan Milanovic
> > wrote:
> >
> > > Hi,
> > >
> > > I have one int (myInt) in my action class, and I want to iterate in my
> > jsp
> > > from 0 to that int (myInt), how can I do this ?
> > >
> > > I tried like this:
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > But it only writes its value, it doesn't iterate at all.
> > >
> > > --
> > > Thx, Milan
> > >
> > >
> >
> >
> >
> >
> > --
> > Jim Kiley
> > Technical Consultant | Summa
> > [p] 412.258.3346 [m] 412.445.1729
> > http://www.summa-tech.com
> >
> >
> >
> >
>
>
>
> --
> Jim Kiley
> Technical Consultant | Summa
> [p] 412.258.3346 [m] 412.445.1729
> http://www.summa-tech.com
>
>
>
>



-- 
Jim Kiley
Technical Consultant | Summa
[p] 412.258.3346 [m] 412.445.1729
http://www.summa-tech.com

Re: [Struts 2] How to iterate to simple value ?

Posted by Milan Milanovic <mi...@yahoo.com>.
Do you mean this example:

o simulate a simple loop with iterator tag, the following could be done. It does the loop 5 times.   
<s:iterator status="stat" value="{1,2,3,4,5}" >
   <!-- grab the index (start with 0 ... ) -->
   <s:property value="#stat.index" />

   <!-- grab the top of the stack which should be the -->
   <!-- current iteration value (0, 1, ... 5) -->
   <s:property value="top" />
</s:iterator>

?

But this iterator uses an array ?

--
Thx, Milan

 



Jim Kiley <jh...@summa-tech.com> wrote: Read the example at the bottom of the URL I provided.  That is one
solution.  You may be able to come up with your own.  I encourage you to do
so if you are dissatisfied with that example.

On Fri, May 30, 2008 at 10:08 AM, Milan Milanovic 
wrote:

> O.K.
>
> But is there any solution to this, besides putting that value into an array
> ?
>
> --
> Thx, Milan
>
> Jim Kiley  wrote: You can only iterate over an
> array or a Collection -- something that has an
> iterator() method.  Integers (and particularly ints) don't.  If you had
> looked up the iterator tag at
> http://cwiki.apache.org/WW/iterator.htmlbefore mailing the list, you
> would have seen at the bottom of the page an
> example of emulating a simple counter loop.
>
> That same page indicates that if you provide just a single non-iterable
> value, it will be placed into a List, which is subsequently iterated over.
> That is why you are seeing just your one value once.
>
> jk
>
> On Fri, May 30, 2008 at 9:58 AM, Milan Milanovic
> wrote:
>
> > Hi,
> >
> > I have one int (myInt) in my action class, and I want to iterate in my
> jsp
> > from 0 to that int (myInt), how can I do this ?
> >
> > I tried like this:
> >
> >
> >
> >
> >
> >
> >
> >
> > But it only writes its value, it doesn't iterate at all.
> >
> > --
> > Thx, Milan
> >
> >
>
>
>
>
> --
> Jim Kiley
> Technical Consultant | Summa
> [p] 412.258.3346 [m] 412.445.1729
> http://www.summa-tech.com
>
>
>
>



-- 
Jim Kiley
Technical Consultant | Summa
[p] 412.258.3346 [m] 412.445.1729
http://www.summa-tech.com


       

Re: [Struts 2] How to iterate to simple value ?

Posted by Jim Kiley <jh...@summa-tech.com>.
Read the example at the bottom of the URL I provided.  That is one
solution.  You may be able to come up with your own.  I encourage you to do
so if you are dissatisfied with that example.

On Fri, May 30, 2008 at 10:08 AM, Milan Milanovic <mi...@yahoo.com>
wrote:

> O.K.
>
> But is there any solution to this, besides putting that value into an array
> ?
>
> --
> Thx, Milan
>
> Jim Kiley <jh...@summa-tech.com> wrote: You can only iterate over an
> array or a Collection -- something that has an
> iterator() method.  Integers (and particularly ints) don't.  If you had
> looked up the iterator tag at
> http://cwiki.apache.org/WW/iterator.htmlbefore mailing the list, you
> would have seen at the bottom of the page an
> example of emulating a simple counter loop.
>
> That same page indicates that if you provide just a single non-iterable
> value, it will be placed into a List, which is subsequently iterated over.
> That is why you are seeing just your one value once.
>
> jk
>
> On Fri, May 30, 2008 at 9:58 AM, Milan Milanovic
> wrote:
>
> > Hi,
> >
> > I have one int (myInt) in my action class, and I want to iterate in my
> jsp
> > from 0 to that int (myInt), how can I do this ?
> >
> > I tried like this:
> >
> >
> >
> >
> >
> >
> >
> >
> > But it only writes its value, it doesn't iterate at all.
> >
> > --
> > Thx, Milan
> >
> >
>
>
>
>
> --
> Jim Kiley
> Technical Consultant | Summa
> [p] 412.258.3346 [m] 412.445.1729
> http://www.summa-tech.com
>
>
>
>



-- 
Jim Kiley
Technical Consultant | Summa
[p] 412.258.3346 [m] 412.445.1729
http://www.summa-tech.com

Re: [Struts 2] How to iterate to simple value ?

Posted by Milan Milanovic <mi...@yahoo.com>.
O.K.

But is there any solution to this, besides putting that value into an array ?

--
Thx, Milan

Jim Kiley <jh...@summa-tech.com> wrote: You can only iterate over an array or a Collection -- something that has an
iterator() method.  Integers (and particularly ints) don't.  If you had
looked up the iterator tag at
http://cwiki.apache.org/WW/iterator.htmlbefore mailing the list, you
would have seen at the bottom of the page an
example of emulating a simple counter loop.

That same page indicates that if you provide just a single non-iterable
value, it will be placed into a List, which is subsequently iterated over.
That is why you are seeing just your one value once.

jk

On Fri, May 30, 2008 at 9:58 AM, Milan Milanovic 
wrote:

> Hi,
>
> I have one int (myInt) in my action class, and I want to iterate in my jsp
> from 0 to that int (myInt), how can I do this ?
>
> I tried like this:
>
> 
>        
>            
>        
>        
> 
>
> But it only writes its value, it doesn't iterate at all.
>
> --
> Thx, Milan
>
>




-- 
Jim Kiley
Technical Consultant | Summa
[p] 412.258.3346 [m] 412.445.1729
http://www.summa-tech.com


       

Re: [Struts 2] How to iterate to simple value ?

Posted by Jim Kiley <jh...@summa-tech.com>.
You can only iterate over an array or a Collection -- something that has an
iterator() method.  Integers (and particularly ints) don't.  If you had
looked up the iterator tag at
http://cwiki.apache.org/WW/iterator.htmlbefore mailing the list, you
would have seen at the bottom of the page an
example of emulating a simple counter loop.

That same page indicates that if you provide just a single non-iterable
value, it will be placed into a List, which is subsequently iterated over.
That is why you are seeing just your one value once.

jk

On Fri, May 30, 2008 at 9:58 AM, Milan Milanovic <mi...@yahoo.com>
wrote:

> Hi,
>
> I have one int (myInt) in my action class, and I want to iterate in my jsp
> from 0 to that int (myInt), how can I do this ?
>
> I tried like this:
>
> <s:iterator value="myInt" status="iterstatus">
>        <s:url id="url" action="list.action">
>            <s:param name="myInt"><s:property/></s:param>
>        </s:url>
>        <s:a href="%{url}"><s:property/></s:a>
> </s:iterator>
>
> But it only writes its value, it doesn't iterate at all.
>
> --
> Thx, Milan
>
>




-- 
Jim Kiley
Technical Consultant | Summa
[p] 412.258.3346 [m] 412.445.1729
http://www.summa-tech.com