Struts2 jstl iterator tag

I was looking at how to implement a thing in struts2 jstl, but I cannot find a way.

When I load a jsp page from an action, I have a list of string lists.

I want to create as divs, since the elements have a list, but inside each div I want to create a link as the third element of this sub-list.

Therefore, I use the s: iterator tag to parse the list. But I don’t know how to repeat "$ {item [2]}" times inside the first iterator.

The code would be something like this:

<s:iterator value="functions" var="item" status="stat">
        <span class="operation">${item[1]}</span>
        <div id="${item[0]}">
            <s:for var $i=0;$i<${item[2]};$i++>
                <a href="#" id="link_$i">Link $i</a>
            </s:for>
        </div>
</s:iterator>

Where I put the s: for tag, where I would like to repeat "$ {item [2]}" times ...

Can anybody help me?

Thank you very much in advance, Aleix

+3
source share
2 answers

Make sure you have the main JSTL library in the area on the JSP page:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<c:forEach>. - :

<c:forEach var="i" begin="0" end="${item[2] - 1}">
    <a href="#" id="link_${i}">Link ${i}</a>
</c:forEach>
+2

List of Map, :

// List of raw type Map
private List<Map> functions = Lists.newArrayList(); // with getter

@Override
public String execute() {
    // loops {
        Map map = Maps.newHashMap();
        map.put("id", id);
        map.put("operation", operation);
        map.put("count", count); // count is int/Integer
        functions.add(map);
    // }

    return SUCCESS;
}

.jsp

<s:iterator value="functions">
    <span class="operation">${operation}</span>
    <div id="${id}">
        <s:iterator begin="0" end="count - 1" var="link">
            <a href="#" id="link_${link}">Link ${link}</a>
        </s:iterator>
    </div>
</s:iterator>


<s:a /> ()

<s:a action="action_name" id="%{link}" anchor="%{link}">Link ${link}</s:a>

<a id="[id]" href="/namespace/action#[anchor]">Link [link]</a>

.

Struts2 Guidess: iterator

+1

All Articles