java - How to do for each in Struts 2 -


i trying build slider web page in html. gets values arraylist(named testlist) struts action. , want display 6 values list @ time in pattern.for ex:

if array of size 26, {0,1,2,3,4,5} {6,7,8,9,10,11} {11,12,13,14,15} .. , on upto {24,25} ,rest values if null ok.

something each loops: for(i=0;i<size;i+6){}

but values list in pattern :

{0,1,2,3,4,5} {1,2,3,4,5,6} {2,3,4,5,6,7} ..

which because index(#status.index)iterates in following pattern {0,1,2,3...} want index increment 6 everytime instead of 0 1 2 etc.

i added step="6" , not working.

here sample of code below:

 <ul class="slider">         <s:iterator step="6" status="status" value="testlist" >         <li> <!-- first slot of data -->              <div class="rightsubcontainer">                     <s:iterator value="testlist[#status.index]" >                         <table >                             <tr>                                 <th>                                     <p align="center"><b ><font color="#151b54"><s:property value="name" /></font></b></p>                                 </th>                             </tr>                         </table>                         <!-- ...values  -->                     </s:iterator>                    </div>             <div class="rightsubcontainer">                     <s:iterator value="testlist[#status.index+1] " >                         <table >                             <tr>                                 <th>                                     <p align="center"><b ><font color="#151b54"><s:property value="name" /></font></b></p>                                 </th>                             </tr>                         </table>                         <!-- ...values  -->                     </s:iterator>                    </div>             <div class="rightsubcontainer">                     <s:iterator value="testlist[#status.index+2]" >                         <table >                             <tr>                                 <th>                                     <p align="center"><b ><font color="#151b54"><s:property value="name" /></font></b></p>                                 </th>                             </tr>                         </table>                         <!-- ...values  -->                     </s:iterator>                </div>             <!-- ... , on.. upto 6 values --> 

why 1 table each value ? why 1337 iterators instead of single 1 ? why <b>, <font> etc instead of using css ?

by way need use % (module operator) check if current position multiple of six; if is, need split <li>;

note iteratorstatus.count same iteratorstatus.index + 1, because 1-based;

ugly way:

<ul class="slider">     <li>         <s:iterator status="status" value="testlist" >                           <table >                     <tr>                         <th>                             <p align="center"><b ><font color="#151b54">                                 <s:property value="name" />                             </font></b></p>                         </th>                     </tr>                 </table>             <s:if test="%{#status.count % 6 == 0}" >                 </li>                 <li>             </s:if>         </s:iterator>     </li> </ul> 

better way:

<ul class="slider">     <li>         <s:iterator status="status" value="testlist" >                           <p>                     <s:property value="name" />                 </p>             <s:if test="%{#status.count % 6 == 0}" >                 </li>                 <li>             </s:if>         </s:iterator>     </li> </ul> 

and in css (or inside <style></style> block in <head> element)

ul.slider > li > p {     text-align: center;     color: #151b54;     font-weight: bold;     background-color: #ddd; } 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -