Good day!
Using Struts2 iterator tag, I need to create the div wherein there would be 3 items per div.
My code is as follows:
<s:iterator value="sampleList">
<s:if test="%{#sampleList%3==0}" >
<div>
</s:>
<s:property value="name">
<s:property value="address">
<s:if test="%{#sampleList%3==0}" >
</div>
</s:>
</s:iterator>
The code above separates the start and end tag of the <div></div> causing the page to have a warning. Is there other ways I could implement this better using other struts technique or javascript.
Thank you.
You shouldn’t care about this warning. The IDE does its best to warn you about potential HTML problems, but what matters is the validity of the generated HTML. Your code will generate correct HTML, so it’s OK.
On the other hand, its logic is flawed, and it won’t generate the HTML you’re expecting. You will have a div every 3 elements, but the div will only contain one. The
</div>should be generated whensampleList % 3 == 2or when the end of the list has been reached.