Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to append loop index of c:forEach tag to Struts HTML tag attributes?
    primarykey
    data
    text
    <p>How can I append the loop index of a c:forEach tag to the attributes of a struts select/text tag?</p> <p>For example.</p> <pre><code>&lt;%@ taglib uri="/WEB-INF/tld/struts-html.tld" prefix="html"%&gt; &lt;c:forEach begin="2" end="${pageView.guestCount}" varStatus="gC"&gt; &lt;div class="section guest-details"&gt; &lt;html:select property='title_guest&lt;c:out value="${gC.index}"/&gt;'&gt; &lt;html:options collection="titles" property="code" labelProperty="value" /&gt; &lt;/html:select&gt; &lt;/div&gt; &lt;/c:forEach&gt; </code></pre> <p>throws the following error </p> <p><code>javax.servlet.jsp.JspException at org.apache.struts.taglib.html.SelectTag.calculateMatchValues(SelectTag.java:246)</code></p> <p>Now, when I debug the code at <code>&lt;html:select ...</code> it shows that when the property attribute it set, its set as <code>"title_guest&lt;c:out value="${gC.index}"/&gt;"</code> which could be the cause of the exception above.</p> <p>Also, I should mention, that if I use the above format for appending the loop index to a standard html tag attribute like a <code>&lt;select&gt;</code> tag, the code works fine.</p> <p>For example</p> <pre><code>&lt;c:forEach begin="2" end="${pageView.guestCount}" varStatus="gC"&gt; &lt;div class="section guest-details"&gt; &lt;select name='title_guest&lt;c:out value="${gC.index }"/&gt;'&gt; &lt;option value=""&gt;Select Title&lt;/option&gt; &lt;/select&gt; &lt;/div&gt; &lt;/c:forEach&gt; </code></pre> <p>Correctly outputs the intended HTML</p> <p>What am I doing wrong, should I be using EL to create the string that will populate the "property" attribute of the html:select tag? </p> <p><strong>UPDATE</strong></p> <p>The following snippet was also tried and that didn't work either <code>&lt;html:select property="title_guest${gC.index}"&gt;</code></p> <p>And, neither does this work</p> <pre><code>&lt;c:set var="guestTitle"&gt;title_guest${gC.index}&lt;/c:set&gt; &lt;html:select property="${guestTitle}" styleClass="{required: true}"&gt; &lt;html:options collection="titles" property="code" labelProperty="value" /&gt; &lt;/html:select&gt; </code></pre>
    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.
    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