Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4624756
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:10:27+00:00 2026-05-22T03:10:27+00:00

How can I append the loop index of a c:forEach tag to the attributes

  • 0

How can I append the loop index of a c:forEach tag to the attributes of a struts select/text tag?

For example.

<%@ taglib uri="/WEB-INF/tld/struts-html.tld" prefix="html"%>

<c:forEach begin="2" end="${pageView.guestCount}" varStatus="gC">
    <div class="section guest-details">
       <html:select property='title_guest<c:out value="${gC.index}"/>'>
          <html:options collection="titles" property="code" labelProperty="value" />
       </html:select>
    </div>
 </c:forEach>

throws the following error

javax.servlet.jsp.JspException at org.apache.struts.taglib.html.SelectTag.calculateMatchValues(SelectTag.java:246)

Now, when I debug the code at <html:select ... it shows that when the property attribute it set, its set as "title_guest<c:out value="${gC.index}"/>" which could be the cause of the exception above.

Also, I should mention, that if I use the above format for appending the loop index to a standard html tag attribute like a <select> tag, the code works fine.

For example

<c:forEach begin="2" end="${pageView.guestCount}" varStatus="gC">
  <div class="section guest-details">
      <select name='title_guest<c:out value="${gC.index }"/>'>
            <option value="">Select Title</option>
      </select>
  </div>
</c:forEach>

Correctly outputs the intended HTML

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?

UPDATE

The following snippet was also tried and that didn’t work either
<html:select property="title_guest${gC.index}">

And, neither does this work

<c:set var="guestTitle">title_guest${gC.index}</c:set>
<html:select property="${guestTitle}" styleClass="{required: true}">
 <html:options collection="titles" property="code" labelProperty="value" />
</html:select>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T03:10:28+00:00Added an answer on May 22, 2026 at 3:10 am

    After some painful digging around, I seemed to have found the problem and hence the solution. The c:forEach tag does not export the varStatus as a scripting variable and therefore the varStatus variable can not be used in the RT Expr for the property attribute of the html:select tag.

    However, the c:forEach does export the varStatus variable as a pageContext attribute, which can be retrieved and used to extract the index/count. The only catch is that you will have to import the javax.servlet.jsp.jstl.core.LoopTagStatus class and use that to manually recreate the varStatus variable so that it can be used inside a scriplet

    Here’s the snippet of code that worked

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        import="javax.servlet.jsp.jstl.core.LoopTagStatus"
    %>
     ...
    <c:forEach begin="2" end="${pageView.guestCount}" varStatus="gC">
      <% LoopTagStatus gN = (LoopTagStatus)pageContext.getAttribute("gC"); %>
      <html:select property='<%="title_guest"+gN.getIndex()%>'>
         <html:options collection="titles" property="code" labelProperty="value" />
      </html:select>
    </c:forEach>
    

    I don’t think this is a clean solution (but could be the only solution). Therefore, I will let the community vote on this answer first (or write a better answer), before I accept it as the final answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to append to a string in a for loop. I can
Is there a command that can append one array of char onto another? Something
If I have some R list mylist , you can append an item obj
How can I append this <% =i %> variable onto this. <asp:DropDownList ID=AdTitle runat=server>
How can i append 2nd page of a pdf file to the first page.
in F#, array.append can join two arrays; is there a way to append 2
Can extensive StringBuilder.Append() operations be optimized by using char[] allocated on thread's stack to
I would like some container that I can very efficiently append a variable amount
I can't make the delay function of jQuery works with append function. What is
I can fetch the item names from a database and append them to an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.