• Post Reply Bookmark Topic Watch Topic
  • New Topic

Display the array length using JSTL

 
Romeo Ranjan
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am looping through an array and here is my code



The problem is the output i get

Count 1
Count 2
Count 3


It loops through the array and prints each time. What I want is I want to assign
the count to a variable and display the count like this.

Count 3


How do I go about doing this?
 
D. Ogranos
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't really get what you want to achieve here? The count value IS already in a variable you can print out (status.count), and it comes out in the form you want. Or do you only want to print it if count has a specific value (like 3 here)? You can check that using


 
Romeo Ranjan
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
D. Ogranos wrote:I don't really get what you want to achieve here? The count value IS already in a variable you can print out (status.count), and it comes out in the form you want. Or do you only want to print it if count has a specific value (like 3 here)? You can check that using




Thank you very much for the reply. Sorry for not being clear. I want only the final count value alone. Everytime it loops through it prints Count 1 Count 2 and so on.
But what I want is the total count alone, only the value 3. How can I achieve this? Hope I am clear
 
Paul Clapham
Sheriff
Posts: 21884
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of outputting the count value, just assign it to a variable. Then output that variable after the loop is finished.
 
Romeo Ranjan
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Instead of outputting the count value, just assign it to a variable. Then output that variable after the loop is finished.


Hi Paul

Would be possible for you to show an example so that I could learn?

Thanks
 
Paul Clapham
Sheriff
Posts: 21884
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which one are you having trouble with? Assigning something to a variable, or displaying the value of a variable?

Edit: No, never mind. I see you already know how to display the value of a variable. So it must be assigning something to a variable which is your question. You would use theelement for that.
 
Romeo Ranjan
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Which one are you having trouble with? Assigning something to a variable, or displaying the value of a variable?

Edit: No, never mind. I see you already know how to display the value of a variable. So it must be assigning something to a variable which is your question. You would use theelement for that.




Is it something like this?
 
Romeo Ranjan
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found out. Thanks a lot for helping me learn.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!