• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Why am I getting The end tag "forEach" is unbalanced and how to know the index of the List?

 
Ranch Hand
Posts: 1021
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to find out the length of the arraylist I am publishing to JSTL in JSP so here's what I did :



And could someone also advise me how do I know if is the way to find out if the element in the list is at which index ?

Thanks.
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check out https://docs.oracle.com/javaee/6/api/javax/servlet/jsp/jstl/core/LoopTagStatus.html to see other properties of varStstus you can use.
 
tangara goh
Ranch Hand
Posts: 1021
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Junilu Lacar wrote:Check out https://docs.oracle.com/javaee/6/api/javax/servlet/jsp/jstl/core/LoopTagStatus.html to see other properties of varStstus you can use.



Hi Junilu,

I have read the link.  However, I do not think you can use .getCount() inside JSP/JSTL right ?

Anyway, I get to learn .count from stackoverflow ...

Could you let me know why am I getting that error ?

Cos I have closed off <c:/forEach> so why is it unbalanced ?

Anyway I can find out what unbalanced mean ?
 
Junilu Lacar
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you notice, getCount() becomes .count in JSTL. All the other properties are accessed similarly. Read the JavaDoc descriptions carefully: they all say what the attribute is that you need to use in JSTL.

I don't know about the other error you're dealing with. "Unbalanced" simply means that the end tag is not paired up properly with a begin tag. What you showed seems to be paired up properly though.
 
Marshal
Posts: 4499
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

tangara goh wrote:Cos I have closed off <c:/forEach> so why is it unbalanced ?


I see two problems with your markup:

1. The first <c:forEach> tag is self-closing, but you have a </c:forEach> tag later-on in the document.
2. There doesn't appear to be an opening <table> tag anywhere.
 
tangara goh
Ranch Hand
Posts: 1021
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ron McLeod wrote:

tangara goh wrote:Cos I have closed off <c:/forEach> so why is it unbalanced ?


I see two problems with your markup:

1. The first <c:forEach> tag is self-closing, but you have a </c:forEach> tag later-on in the document.
2. There doesn't appear to be an opening <table> tag anywhere.

Hi Ron, Even after removing the / at the varStatus I am still getting same error :( I have further removed all the / that is under each </td>

 
Saloon Keeper
Posts: 15510
363
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You know, you can easily solve these problems by yourself if you just format your code correctly:

XML tags must either have a closing tag, or must be self closing. I can count 4 unclosed start tags, and one closing tag without a start tag.

By the way, did you mean to enclose the last four counts in double quotes? That's not necessary for XML element values.
 
tangara goh
Ranch Hand
Posts: 1021
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:You know, you can easily solve these problems by yourself if you just format your code correctly:

XML tags must either have a closing tag, or must be self closing. I can count 4 unclosed start tags, and one closing tag without a start tag.

By the way, did you mean to enclose the last four counts in double quotes? That's not necessary for XML element values.



Thanks for your hints.  I got it.  I guess I am exhausted and flat from coping with so much things...i wonder if other people will get this kind of tiredness...

Anyway, I hope to seek your advice on why I still can't get the list to be printed after adding this :



as suggested by this : https://stackoverflow.com/questions/15905055/jstl-message-dont-know-how-to-iterate-over-supplied-items-with-foreach



 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to display everything in the list, why are you using the begin.end attributes of the tag?
 
tangara goh
Ranch Hand
Posts: 1021
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Tolls wrote:If you want to display everything in the list, why are you using the begin.end attributes of the tag?



Because it is not printing everything.  It only printed the first row.

Hence, at first I tried to use {fn:length(users)} to see if it captured the length of the attributes users.

But, it will give me error even though I have put in the import fn Taglib.

 
Stephan van Hulst
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Get rid of the attributes. Show us the latest version of your code, and the error message.
 
tangara goh
Ranch Hand
Posts: 1021
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:Get rid of the attributes. Show us the latest version of your code, and the error message.



The problem is that there isn't any error at all.  And with the added fn:users.length, it is not printing anything at all....as in not showing that row of data earlier on.
 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, so show us the output.
Without those extra attributes.

Show the HTML produced.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic