JSP Expression Problem

Posted on 2008-11-07
Last Modified: 2013-12-02
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++;%>


		<html:select property="type" styleClass="" styleId="select<%=i%>" name="companyDetails" onchange="checkFields('<%=i%>')">

			<html:options collection="GetNumberTypeObj" property="optionValue" labelProperty="optionText"/>




		<html:select property="country" styleClass="" styleId="hideEmail<%=i%>" 	name="companyDetails">

			<html:options collection="GetCountryObj" property="optionValue" labelProperty="optionText"/>



		<td><html:text name="companyDetails" property="number"/></td>

		<td><html:text name="companyDetails" property="defaults"/></td>



Open in new window

Question by:jacoalb
    1 Comment

    Accepted Solution

    Turns out struts gets confused by



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

    is required.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Suggested Solutions

    Title # Comments Views Activity
    Using Tomcat as raspberry pi java app server 13 76
    has22 challenge 11 56
    only14 challenge 19 57
    mapShare challenge 13 40
    Configure Web Service (server application) I. Configure security for Web Services methods First, we need to protect Session bean which implements the service: 1. Open EJB deployment descriptor (ejb-jar.xml) in the EJB project that contains you…
    Upgrading Tomcat – There are a couple of methods to upgrade Tomcat is to use The Apache Installer is to download and unzip and run the services.bat remove|install Tomcat6 Because of the App that we are working with, we can only use Tomcat 6.…
    The viewer will learn how to implement Singleton Design Pattern in Java.
    This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now