JSP Expression Problem

Hey all.

I am getting a very confusing problem in one of my jsps.
I need to loop through an Arraylist object, and display each object in a table on my page.
Two of the properties must be displayed in dropdown lists(html:select). These need to be accessable from javascript, as when you set the first one to a specific value, the second one must be set to disabled. Seeing as there could be any amount of them, I need to set the Ids as I iterate through the list, with an incrementing number, and the use the <%= %> tags to add it to the end. So the the id for the first html:select is styleId="select<%=i%>", where i is the int that increments. So the ids should be select1, select2, select3 etc... if im not mistaken... which I guess I must be. It is the same for the other select, styleId="hideEmail<%=i%>", and I call the javascript method like so: onchange="checkFields('<%=i%>')".
I tried displaying the value in an alert in the javascript, and it displays <%=i%> in the alert...
It should be showing 1. As far as i can see anyway...

Any assistance or insight would be greatly appreciated.

Thanks in advance.
<% int i=0;%>
<logic:iterate id="companyDetails" name="CompanyDetailsObj">
	<% if( i % 2 == 0) {%><tr class="even"><%}else{%>
	<tr><%} i++;%>
		<td>
		<html:select property="type" styleClass="" styleId="select<%=i%>" name="companyDetails" onchange="checkFields('<%=i%>')">
			<html:options collection="GetNumberTypeObj" property="optionValue" labelProperty="optionText"/>
		</html:select>
		</td>
		<td>
		<html:select property="country" styleClass="" styleId="hideEmail<%=i%>" 	name="companyDetails">
			<html:options collection="GetCountryObj" property="optionValue" labelProperty="optionText"/>
		</html:select>
		</td>
		<td><html:text name="companyDetails" property="number"/></td>
		<td><html:text name="companyDetails" property="defaults"/></td>
	</tr>
</logic:iterate>

Open in new window

jacoalbAsked:
Who is Participating?
 
jacoalbConnect With a Mentor Author Commented:
Turns out struts gets confused by

styleId="hideEmail<%=i%>"

so

<% String selectId="select"+String.valueOf(i); %>
 styleId="<%= selectId %>"

is required.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.