Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

struts html: tags within jstl forEach

 
ralphy orientis
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hiya,

I have scoured the net for solutions to this, and have found little.
Perhaps I am missing something obvious but I was surprised because I thought this would be one of the most common things required in a Struts app !

I'd like to have a number of radio input fields on a form, when the IDs and properties contain their respective numbers. Given that there will be a variable number of radios, I'd like to render them dynamically from a c:forEach tag (the jstl equivalent of logic:iterate).

My aproximate goal is :

<input type="radio" id="opt1" name="optRads" value="val1"/>
<input type="radio" id="opt2" name="opRads" value="val2"/>
<input type="radio" id="opt3" name="opRads" value="val3"/>
etc

This is my foiled attempt :

<c:forEach var='i' begin='1' end='3'>
<html:radio styleId="${i}RadioInput" property="opRads" value="val${i}"/>
</c:forEach>

I've surrounded the var i in ${} to highlight where I want the dynamic content.

The result of this and all my other efforts including the following :

<c:forEach var='i' begin='1' end='3'>
<html:radio styleId="<%=i%>RadioInput" property="opRads" value="val<%=i%>}"/>
</c:forEach>

seem to fail. Please help, anyone who knows this most esoteric mystery !

Anthony
 
alan do
Ranch Hand
Posts: 354
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
to use expression language, you must use the EL tags for corresponding libraries. eg, there is html_el:radio tag that will understand the ${i}. <c:forEach
<html_el:radio styleId="${i}RadioInput" property="opRads" value="val${i}"/>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic