• 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

Displaying alternative text when a tag's body is empty

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic