Compute index module int Struts2 iterator

I am using the Struts2 iterator to set a list of checkboxes in a table. I want to have 10 checkboxes per line, so I do the following:

<table> <tr> <s:iterator value="securityMasterFields" status="fieldNameStatus" var="fieldName"> <s:if test="#fieldNameStatus.index % 10 ==0"> </tr><tr> </s:if> <td> <s:checkbox name="fieldsToShow" fieldValue="%{fieldName}" value="%{fieldName}"/> </td> </s:iterator> </tr> </table> 

It never goes through if, so I assume the mod is not calculated correctly. How to do it?

thanks

+4
source share
2 answers

Well, I had to add some parentheses and it worked correctly. The loop worked, it was just that it did not go through if.

 <s:if test="(#fieldNameStatus.index % 8 )==0"></tr><tr></s:if> 
+5
source

It looks good to me. Two thoughts:

1) try to print the test result in the s: property tag

2) It looks like you will have empty rows in the table ... You are looking at the generated html or just the output, because if it is only output, unless you have CSS that gives you some tables and borders, without an empty element " td "line can crash and make it look like nothing is being added. So make sure you also print empty td elements!

+1
source

Source: https://habr.com/ru/post/1332063/


All Articles