?
Solved

JSP for loop issue during creation of JavaScript Object in JSP page

Posted on 2008-10-14
3
Medium Priority
?
911 Views
Last Modified: 2008-11-05
I created  an Object list based on below class and send that over to JSP page  
List<list> account = ArrayList<String> ()         <----- list of account

List<?> myList = new Client( clientId , account  )     <-----   Object that will be sent to JSP


class Client {
    String clientId;
    List<String> accountList;

}

Below is the list content that I iterate before sending to JSP page  to make sure the data in a list are correct:

                  clinetID        account          
Index[0] = 15E5Y8------15E5Y8A
Index[1] = 15E6L8------No Account.
Index[2] = 15E882------15E882A
Index[3] = 15E8L8------15E8L8A
Index[4] = 15E8L8------15E8L8B
Index[5] = 15E8R6------No Account.
Index[6] = 15E9M9------15E9M9A

in order to create the Javascript Object I have made below Script

<script type="text/javascript">
      var clientObjectList = new Array();        
      function Client(clientId,accountId) {
                this.clientId=clientId;
                this.accountId = accountId;
      }  

<c:forEach var="view" items="${sessionScope.keyValueResult.key }"  varStatus="status">      
  <c:set var="listAccount" value="${view.accountList}" />
  <c:forEach var="viewAccount" items="${listAccount}" varStatus="listStatus">
   clientObjectList[${status.count - 2 + listStatus.count}] = new Client("${view.clientId}","${viewAccount}");
</c:forEach>
</c:forEach>  
</scrip>


below is my JavaScript Object list after running the JSP page

      clientObjectList[0] = new client("15E5Y8" , "15E5Y8A");

      clientObjectList[1] = new client("15E6L8" , "No Account in .")

      clientObjectList[2] = new client("15E882" , "15E882A");

      clientObjectList[3] = new client("15E8L8" , "15E8L8A");

      clientObjectList[4] = new client("15E8L8" , "15E8L8B");       

       the next one should be 5 but it's 4
      clientObjectList[4] = new client("15E8R6" , "No Account .");      

      clientObjectList[5] = new client("15E9M9","15E9M9B");            

Please look at the next index after  clientObjectList[4]   --> Must be 5 but it's getting 4 also

Problem :  it seems  when the list has a size more than 1  the index or var="status.count" is  not increased  when iteration is done in nested FOR <c:foreach var="viewAccount")

I did couple different way of programming syntax but the result were the same, something ike below  

<c:set var="index" value="0" />
<c:forEach var="view" items="${sessionScope.keyValueResult.key }"  varStatus="status">      
<c:forEach var="viewAccount" items="${listAccount}" varStatus="listStatus">            
clientObjectList[${index}] = new Client("${view.clientId}","${viewAccount}");
<c:set var="index" value="${index + 1}" />
</c:forEach>
</c:forEach>  

Does anybody have any Ideas ? Thanks
0
Comment
Question by:arkhls
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 17

Expert Comment

by:sweetfa2
ID: 22717633
  clientObjectList[${status.count - 2 + listStatus.count}] = new Client("${view.clientId}","${viewAccount}");

maybe should be:

   clientObjectList[${status.count} - 2 + ${listStatus.count}] = new Client("${view.clientId}","${viewAccount}");
0
 

Author Comment

by:arkhls
ID: 22717678
Tnx for respond , I did  that already unfortunatelt it's not working
0
 
LVL 17

Accepted Solution

by:
sweetfa2 earned 750 total points
ID: 22717692
The problem is in the way you are calculating the index.  So why are you subtracting to from status.count.

Presumably as status.count is the outer loop the actual number of entries will be different for each iteration.  May I suggest a simple incrementing count value every time you add or maybe use clientObjectList.length as the index instead.

It may be clientObjectList.size() but I can't remember at the moment.

0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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.
Suggested Courses

762 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