Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Debug JSTL

 
James Ellis
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new to JSTL and I'm trying to debug a forEach statement that is iterating through the columns in one row pulled from a database. The value of the column is not printing correctly when it's empty and I'm having a hard time figuring out why. Here is the code:



If the value is not empty, the value is displayed. While if it IS empty, the "-" should display (but it's not). In fact I can't get anything to display if the value of the column variable is blank/null.

Two questions:

1) Does anyone know what is wrong with this ternary statement?

2) Is it possible to print out the value of the column variable using a scriptlet and System.out.println so that I can have a clue what is going on with this variable?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A couple of things:

1) Please check the 'disable smilies' checkbox when posting code. That way, your <cut> tags will look less surprised!

2) I am assuming JSP 2.0 and JSTL 1.1? The ternary operator is not supported in earlier versions.

3) The forEach tag will create its var in pageContext, so for debugging purposes you could fetch it from there in order to examine it.
 
James Ellis
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the pageContext hint. I was able to get the SQL statement that was being called and when I run that directly against the database, the statement returns ALL columns. However, when I run it in through the JSP it is actually skipping 3 of the columns.

However I've found that if I change the


To



All the columns are displayed. What could the "rowsByIndex" be doing here to hide some of these columns?

Thanks,
Jim
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What could the "rowsByIndex" be doing here to hide some of these columns?


You'd have to look at the getRowsByIndex() method of whatever 'stats' is to find out.
 
James Ellis
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all for the suggestions. I found the problem, and it wasn't on the rows or rowsByIndex (although I am still not sure why "rows" was working when according to my debugging, it shouldn't have). The issue was with the



line. The variable "date_format" was null and I suppose these JSTL tags must do some sort of error handler because there was no null pointer exception being thrown.

For anyone who is curious, I had to tear apart the "stats" variable which was a Result object to look at what getRowsByIndex returned and this is how I did it.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic