Note that there are some explanatory texts on larger screens.

plurals
  1. POIterating over an ArrayList with c:foreach (JSP/JSTL), Variable doesn't work
    primarykey
    data
    text
    <p>There are countless examples out there for my problem, I know, but I went through a lot of them and can't figure out where my mistake is.</p> <p>I am iterating over an ArrayList(TestSzenario). The class TestSzenario contains a String Variable called name with proper getters and setters.</p> <p>Here's my code:</p> <pre><code>&lt;td&gt;&lt;select name="selectSzenario" id="selectSzenario" size="1"&gt; &lt;c:forEach items="&lt;%=testszenario.getSzenariosForSummary() %&gt;" var="szenario"&gt; &lt;option&gt;${szenario.name}&lt;/option&gt; &lt;/c:forEach&gt;&lt;/select&gt;&lt;/td&gt;&lt;/tr&gt; </code></pre> <p>My Problem is, the Variable isn't working. I alwas get ${szenario.name} for every option in the select-box. I declared the JSTL-taglib properly and since there are multiple options in the site when done i know the iteration is working. Also I looked in the HTML-sourcecode an the foreach is resolved.</p> <p>HTML-output:</p> <pre><code> &lt;tr&gt;&lt;td&gt;Szenario:&lt;/td&gt; &lt;td&gt;&lt;select name="selectSzenario" id="selectSzenario" size="1"&gt; &lt;option&gt;${szenario.name}&lt;/option&gt; &lt;option&gt;${szenario.name}&lt;/option&gt; &lt;/select&gt;&lt;/td&gt;&lt;/tr&gt; </code></pre> <p>EDIT for answer 1: Thank you, but I tried that before:</p> <pre><code>ArrayList&lt;TestSzenario&gt; szenarioList = testszenario.getSzenariosForSummary(); request.setAttribute("aList", szenarioList); request.setAttribute("ts", testszenario); &lt;c:forEach items="${aList}" var="szenario"&gt; &lt;option&gt;${szenario.name}&lt;/option&gt; &lt;/c:forEach&gt;&lt;/select&gt;&lt;/td&gt;&lt;/tr&gt; &lt;c:forEach items="${ts.szenariosForSummary}" var="szenario"&gt; &lt;option&gt;${szenario.name}&lt;/option&gt; &lt;/c:forEach&gt;&lt;/select&gt;&lt;/td&gt;&lt;/tr&gt; </code></pre> <p>But in either case it doesn't even iterate through the List, resulting in only 1 option (the List contains 2 elements).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload