You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Skip Hollowell <sk...@skipdaddy.com> on 2007/04/26 19:39:48 UTC

[S2]Loop through two arrays in my JSP

I have two Arrays (account.amt and account.date) and while they are both 
the same size, I don't know what that size is until the page gets em.  
If I really needed to I guess I could also put a size field into account.

But what is the best way to loop over them  and grab these values?

I can easily go over one field at a time:
    <s:iterator value="payment.datePaid">
      <s:property/>
    </s:iterator>

I can't seem to find any looping constructs that would get me the index 
each time through and allow me to do something like:
  //index i=0
  <somesortaloopcontracut>
    <s:textfield key="payment.amtToPay" value="%{payment.amtToPay[i]}" 
theme="simple" />
    <s:textfield key="payment.datePaid" value="%{payment.datePaid[i]}" 
theme="simple"/><br>
  //increment my index i
 </s:iterator>


Am I missing some basic way of doing things, or am I way off base on my 
object definitions.  I tried the alternate way, creating an array of 
payments (instead of a payment with an array of dates and an array of 
amounts), with each payment having a date and an amount, but then I 
couldn't update these objects from the form (see earlier post and some 
suggestions from Mike Menard, which I wasn't able to get functioning)


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


Re: [S2]Loop through two arrays in my JSP

Posted by Martin Gainty <mg...@hotmail.com>.
Hi Skip

http://husted.com/struts/tips/006.html
from id of the iterate is then used to reference name 
(for the specific array value indicated by property)

Does this help?
M--
This email message and any files transmitted with it contain confidential
information intended only for the person(s) to whom this email message is
addressed.  If you have received this email message in error, please notify
the sender immediately by telephone or email and destroy the original
message without making a copy.  Thank you.

----- Original Message ----- 
From: "Skip Hollowell" <sk...@skipdaddy.com>
To: <us...@struts.apache.org>
Sent: Thursday, April 26, 2007 1:39 PM
Subject: [S2]Loop through two arrays in my JSP


>I have two Arrays (account.amt and account.date) and while they are both 
> the same size, I don't know what that size is until the page gets em.  
> If I really needed to I guess I could also put a size field into account.
> 
> But what is the best way to loop over them  and grab these values?
> 
> I can easily go over one field at a time:
>    <s:iterator value="payment.datePaid">
>      <s:property/>
>    </s:iterator>
> 
> I can't seem to find any looping constructs that would get me the index 
> each time through and allow me to do something like:
>  //index i=0
>  <somesortaloopcontracut>
>    <s:textfield key="payment.amtToPay" value="%{payment.amtToPay[i]}" 
> theme="simple" />
>    <s:textfield key="payment.datePaid" value="%{payment.datePaid[i]}" 
> theme="simple"/><br>
>  //increment my index i
> </s:iterator>
> 
> 
> Am I missing some basic way of doing things, or am I way off base on my 
> object definitions.  I tried the alternate way, creating an array of 
> payments (instead of a payment with an array of dates and an array of 
> amounts), with each payment having a date and an amount, but then I 
> couldn't update these objects from the form (see earlier post and some 
> suggestions from Mike Menard, which I wasn't able to get functioning)
> 
> 
> ---------------------------------------------------------------------
> 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: [S2]Loop through two arrays in my JSP

Posted by Dave Newton <ne...@yahoo.com>.
--- Skip Hollowell <sk...@skipdaddy.com> wrote:
> I can't seem to find any looping constructs that
> would get me the index [...]

<s:iterator [...] status='stat'>
  <s:property value='#stat.index'/>
</s:iterator>

http://struts.apache.org/2.x/docs/iterator.html

d.


__________________________________________________
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