0

Im trying to introduce some logic into my jsp struts2 page. If a List returned from a session variable is null then I want to iterate over it. If it is non null then I want to use the exising list. Below is my code but the compiler is complaining that their are two iterator being tags but just one end tag.

 <%
            java.util.List eventL = (java.util.List)session.getAttribute("eventList");
            if(eventL != null){
                System.out.println("SIZE LIST IS "+eventL.size());
                %>
                <s:iterator value="eventL" var="event">
                <%
            }
            else 
            {
            %>
            <s:iterator value="eventList" var="event">

            <% } %>

Also am I iterating over the list returned by the session variable correctly ?

Thanks

blue-sky
  • 51,962
  • 152
  • 427
  • 752
  • I have no idea how to achieve this in struts2, but I can at least tell that *scriptlets* and taglibs doesn't share the same variable scope as you'd expect from the coding. There are workarounds (hacks, actually), but the normal practice is to use the one or the other, not both. Since *scriptlets* are discouraged since JSP 2.0 (a decade ago), it's better to go for taglibs only. In other words, get rid of all those `<% %>` things in JSP. See also [How to avoid Java code in JSP files?](http://stackoverflow.com/questions/3177733/how-to-avoid-java-code-in-jsp-files) – BalusC Feb 02 '11 at 21:30

2 Answers2

0
<s:iterate  var="even" value="eventList">
    <s:property value="ListProperty1/>
    <s:property value="ListProperty2/>
    <s:property value="ListProperty3/>
</s:iterate>
xrcwrn
  • 5,339
  • 17
  • 68
  • 129
0

I just added a new struts action and added requested the session variable within the action. The action redirects to the exact same page but used the session variable.

blue-sky
  • 51,962
  • 152
  • 427
  • 752