You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by taj uddin <ta...@yahoo.com> on 2008/12/15 10:59:04 UTC
How to get the int value of current iteration
Hi,
I'm working with an application where i should convert the code that written using <logic:iterate> (i.e struts 1.2) with <s:iterator tag> (struts 2.1).
Below i show the struts1.2 code and also the code which i replaced with <s:iterator> tag
Old code:
//Sub Menu for 2nd Main Menu Item ("Admin"):
menus[1] = new menu(180, "vertical", 0, 0, -1, -1, "", "#ce122d", "Verdana,Helvetica", 8,
"normal", "normal", "white", "#fcccb5", 1, "#ce122d", 2, 62, false, true, false, false, 0, true, 4, 4, "black");
<% int adminIndex = 0; %>
<logic:iterate indexId="idx" id="nfpaTable" name="NfpaTables" scope="session">
<% adminIndex = idx.intValue() + 3; %>
menus[1].addItem("#", "", 20, "left", "<bean:write name="nfpaTable" property="tableName"/>", <%=adminIndex%>);
</logic:iterate>
<% adminIndex++; %>
menus[1].addItem("#", "", 20, "left", "Status", <%=adminIndex%>);
<% adminIndex++; %>
menus[1].addItem("#", "", 20, "left", "Compliance Statement", <%=adminIndex%>);
<% adminIndex++; %>
menus[1].addItem("#", "", 20, "left", "Reference Document", <%=adminIndex%>);
My new code was written using struts2 as shown below:
//Sub Menu for 2nd Main Menu Item ("Admin"):
menus[1] = new menu(180, "vertical", 0, 0, -1, -1, "", "#ce122d", "Verdana,Helvetica", 8,
"normal", "normal", "white", "#fcccb5", 1, "#ce122d", 2, 62, false, true, false, false, 0, true, 4, 4, "black");
<% int adminIndex = 0; %>
<s:iterator value="%{#session.NfpaTables}" status="idx" id="nfpaTable" >
<% adminIndex = "%{#idx.index}" + 3; %>
menus[1].addItem("#", "", 20, "left", "<s:property value="#nfpaTable.tableName" />", <%=adminIndex%>);
</s:iterator>
<% adminIndex++; %>
menus[1].addItem("#", "", 20, "left", "Status", <%=adminIndex%>);
<% adminIndex++; %>
menus[1].addItem("#", "", 20, "left", "Compliance Statement", <%=adminIndex%>);
<% adminIndex++; %>
menus[1].addItem("#", "", 20, "left", "Reference Document", <%=adminIndex%>);
When i run the application, the eclipse shows the error as.........
An error occurred at line: 25 in the jsp file: /includes/header_nfpa.jsp
Type mismatch: cannot convert from String to int
22: <% int adminIndex = 0; %>
23: <s:iterator value="%{#session.NfpaTables}" status="idx" id="nfpaTable" >
24:
25: <% adminIndex = "%{#idx.index}" + 3; %>
26: menus[1].addItem("#", "", 20, "left", "<s:property value="#nfpaTable.tableName" />", <%=adminIndex%>);
27: </s:iterator>
28: <% adminIndex++; %>
So, pls Help me out in this issue.
Re: How to get the int value of current iteration
Posted by Nils-Helge Garli Hegvik <ni...@gmail.com>.
> 25: <% adminIndex = "%{#idx.index}" + 3; %>
Would you normally assume that a String could be assigned to an int variable?
See if you can use the 'set' tag [1] instead.
Nils-H
[1] - http://struts.apache.org/2.0.14/docs/set.html
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org