This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Struts and the fly likes struts html: tags within jstl forEach Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "struts html: tags within jstl forEach" Watch "struts html: tags within jstl forEach" New topic

struts html: tags within jstl forEach

ralphy orientis

Joined: Jul 29, 2005
Posts: 1

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"/>

This is my foiled attempt :

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

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%>}"/>

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

alan do
Ranch Hand

Joined: Apr 14, 2005
Posts: 354
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}"/>

-/a<br />certified slacker...yes, my last name is 'do' - <a href="" target="_blank" rel="nofollow"></a>
I agree. Here's the link:
subject: struts html: tags within jstl forEach
It's not a secret anymore!