This week's book giveaway is in the Java 9 forum.
We're giving away four copies of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications and have Sander Mak & Paul Bakker on-line!
See this thread for details.
Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSTL choose not executing as expected  RSS feed

 
Songezo Nkukwana
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, i have the following JSP file



the c:when test always execute the enclosing body even if members is empty ... Members is a SortedSet (TreeSet), any ideas how else to test for null/empty?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66256
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is the correct way. If the test is succeeding, then members is not empty. Are you sure that it is?
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try <c:out value="${members}" />.

Do you see "[]" ? Then it is empty, otherwise it is not.

Edit: assuming that the toString() of Member class is well-implemented.
 
Songezo Nkukwana
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bauke ... It certainly does show '[]', so then the when test is not working?
 
Songezo Nkukwana
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[quote][i]Edit: assuming that the toString() of Member class is well-implemented[/i][/quote]

Well, its a TreeSet so not sure how its implemented...
 
Songezo Nkukwana
Ranch Hand
Posts: 51
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, it´s time to upgrade then.

I did a quick test here with JSTL 1.2 at JSP 2.1. Works fine.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Songezo Nkukwana wrote:
Edit: assuming that the toString() of Member class is well-implemented


Well, its a TreeSet so not sure how its implemented...

I was talking about the Member class, not about the Set class.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!