开发者

Iterate 2 Lists in parallel in a JSP

I need to iterate through 2 list in paralell in a JSP. I have list1 and list2, and I need to iterate both at same time, or at least access to the list2 with the same index list1 is using, example:

Ideally something like this:

logic:iterate name="list1" id="obje开发者_开发百科ct1" scope="session" indexId="index"

bean:define id="object2" name="list2[index]"

Thanks in advance


I´ve solved the problem with this structure:

<logic:iterate name="list1" id="object1" scope="session" indexId="index">

    <logic:iterate name="list2" id="objAux" scope="session" offset="index" length="1">
        <bean:define id="object2" name="objAux"/>
    </logic:iterate>

...
</logic:iterate>


What about merging these two lists in Java and then iterating resulting list in JSP?

public List<Pair<String, String>> merge(List<String> one, List<String> two)
{
  List<Pair<String, String> result = new ArrayList<Pair<String, String>>();
  for (int i = 0, i < Math.max(one.size(), two.size()); i++)
  {
    result.add(new Pair(one.size < i ? one.get(i) : null, two.size() < i ? two.get(i) : null));
  }
  return result;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜