You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "rinkeh@home.nl" <ri...@home.nl> on 2004/02/26 18:05:21 UTC

row counts in logic:iterate...

<color><param>0100,0100,0100</param>newbie question: 


I have a jsp which displays several rows with a logic:iterate, also 
using the  indexId-tag. 


<color><param>7F00,0000,7F00</param><FontFamily><param>Courier New</param><<logic:iterate<color><param>0000,0000,0000</param> <color><param>0000,7F00,0000</param>name<color><param>0000,0000,0000</param>=<color><param>0000,0000,FF00</param>"dateForm"<color><param>0000,0000,0000</param> <color><param>0000,7F00,0000</param>property<color><param>0000,0000,0000</param>=<color><param>0000,0000,FF00</param>"raw"<color><param>0000,0000,0000</param> 
<color><param>0000,7F00,0000</param>id<color><param>0000,0000,0000</param>=<color><param>0000,0000,FF00</param>"foo"<color><param>0000,0000,0000</param>  <color><param>0000,7F00,0000</param>indexId<color><param>0000,0000,0000</param>=<color><param>0000,0000,FF00</param>"ctr"<color><param>0000,0000,0000</param> <color><param>7F00,0000,7F00</param>><color><param>0000,0000,0000</param> <color><param>0100,0100,0100</param><FontFamily><param>Arial</param> 


I'd like to display row numbers in my table. But the ctr-variable is 0-
based, and I  would like to present 1 as the first number to my 
users.  


Now, this should work, isn't it?? 


<<td><bold><color><param>7F00,0000,0000</param><FontFamily><param>Courier New</param><<%=</bold><color><param>0100,0100,0100</param> <color><param>0000,0000,0000</param>ctr<color><param>0100,0100,0100</param> <color><param>0000,0000,0000</param>+<color><param>0100,0100,0100</param> <color><param>0000,0000,0000</param>1<color><param>0100,0100,0100</param> <bold><color><param>7F00,0000,0000</param>%><</td> 


</bold></color><FontFamily><param>ARIAL</param>I would guess: ctr and 1 are added, and is then cast to a string, 
and then print  it in my table column. 


Then why do i get this error? 


<color><param>0100,0100,0100</param><FontFamily><param>Times New Roman</param><bigger>operator + cannot be applied to java.lang.Integer,int [javac]  

out.print( ctr + 1 );  

                    ^ 

It also does not work when I create a new variabel with <<%! int 
i=0; %>,  and then try to set this i as i = ctr + 1, same error. 


So how can I get this row number printed in my table, inside the 
jsp?? 


Rinke<FontFamily><param>Arial</param><smaller> 



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


RE: row counts in logic:iterate...

Posted by Robert Taylor <rt...@mulework.com>.
First: Please do not send HTML emails to the list.

Now to address your question:

JSTL makes this easy.
<c:forEach var="item" items="${form.items}" varStatus="status">
<tr>
<td><c:out value="${status.count}"/></td>
<td><c:out value="${item.someValue}"/></td>
</tr>
</c:forEach>

Using Struts tags:

<logic:iterate id="item" name="form" property="items" indexId="index">
<tr>
<td><%=indexId.intValue() + 1%></td>
<td><bean:write name="item" property="someValue"/></td>
</tr>
</logic:iterate>

robert

> -----Original Message-----
> From: rinkeh@home.nl [mailto:rinkeh@home.nl]
> Sent: Thursday, February 26, 2004 12:05 PM
> To: struts-user@jakarta.apache.org
> Subject: row counts in logic:iterate...
> 
> 
> <color><param>0100,0100,0100</param>newbie question: 
> 
> 
> I have a jsp which displays several rows with a logic:iterate, also 
> using the  indexId-tag. 
> 
> 
> <color><param>7F00,0000,7F00</param><FontFamily><param>Courier 
> New</param><<logic:iterate<color><param>0000,0000,0000</param> 
> <color><param>0000,7F00,0000</param>name<color><param>0000,0000,0000</param>=<color><param>0000,0000,FF00</param>"dateForm
> "<color><param>0000,0000,0000</param> 
> <color><param>0000,7F00,0000</param>property<color><param>0000,0000,0000</param>=<color><param>0000,0000,FF00</param>"raw"
> <color><param>0000,0000,0000</param> 
> <color><param>0000,7F00,0000</param>id<color><param>0000,0000,0000</param>=<color><param>0000,0000,FF00</param>"foo"<color
> ><param>0000,0000,0000</param>  
> <color><param>0000,7F00,0000</param>indexId<color><param>0000,0000,0000</param>=<color><param>0000,0000,FF00</param>"ctr"<
> color><param>0000,0000,0000</param> <color><param>7F00,0000,7F00</param>><color><param>0000,0000,0000</param> 
> <color><param>0100,0100,0100</param><FontFamily><param>Arial</param> 
> 
> 
> I'd like to display row numbers in my table. But the ctr-variable is 0-
> based, and I  would like to present 1 as the first number to my 
> users.  
> 
> 
> Now, this should work, isn't it?? 
> 
> 
> <<td><bold><color><param>7F00,0000,0000</param><FontFamily><param>Courier 
> New</param><<%=</bold><color><param>0100,0100,0100</param> 
> <color><param>0000,0000,0000</param>ctr<color><param>0100,0100,0100</param> 
> <color><param>0000,0000,0000</param>+<color><param>0100,0100,0100</param> 
> <color><param>0000,0000,0000</param>1<color><param>0100,0100,0100</param> <bold><color><param>7F00,0000,0000</param>%><</td> 
> 
> 
> </bold></color><FontFamily><param>ARIAL</param>I would guess: ctr and 1 are added, and is then cast to a string, 
> and then print  it in my table column. 
> 
> 
> Then why do i get this error? 
> 
> 
> <color><param>0100,0100,0100</param><FontFamily><param>Times New Roman</param><bigger>operator + cannot be applied to 
> java.lang.Integer,int [javac]  
> 
> out.print( ctr + 1 );  
> 
>                     ^ 
> 
> It also does not work when I create a new variabel with <<%! int 
> i=0; %>,  and then try to set this i as i = ctr + 1, same error. 
> 
> 
> So how can I get this row number printed in my table, inside the 
> jsp?? 
> 
> 
> Rinke<FontFamily><param>Arial</param><smaller> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 

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