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

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.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}");

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

Does anybody have any Ideas ? Thanks
Who is Participating?
sweetfa2Connect With a Mentor Commented:
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.

  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}");
arkhlsAuthor Commented:
Tnx for respond , I did  that already unfortunatelt it's not working
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.