Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Displaying alternative text when a tag's body is empty

 
Michael Arnett
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I have a custom tag that does a sql query and displays the results. That works fine. However, I woud like to have an alternate message displayed if there is no results. I think this is easy to handle, but I want to use the standard JSP custom tag method, not some crazy scriptlet or some other exotic method. What is the standardized way of producing alternate text when a tag does not return anything.
Thanks in advance,
-MLA
 
Jeff Grant
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about tossing a counter variable, initialized to 0 beforehand, in your while(ResultSet.next()) loop so it will increment each time the while loop is executed.
This way, once you have exited the loop, you can test that variable to see if it has changed. If so, then you continue because results were returned from the DB. If the variable is still 0, then you exit out and display your suggested text because there were no results which matched your SQL statement.
If that is not the option you were looking for, you could always run two queries. The first being to select the count of the records which would be returned, the next to run the query again returning the actual rows retrieved instead of their count.
 
Sam Dalton
Author
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does the tag have a body already? IF not then try this:
Once you have done your query, check that the rs has data in it, if not then EVAL_BODY_INCLUDE, if it does, display your results and SKIP_BODY at the end.
Cheers
Sam
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic