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
Sun Certified Programmer for the Java 2 Platform 1.4
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.
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
<a href="http://www.samjdalton.com" target="_blank" rel="nofollow">Sam Dalton</a>,<br />Co-author of [http://www.amazon.com/exec/obidos/tg/detail/-/1590592255/qid=1068633302//ref=sr_8_xs_ap_i0_xgl14/104-4904002-9274339?v=glance&s=books&n=507846]Professional JSP 2.0[/URL] (October 2003)<br />Co-author of <a href="http://www.amazon.com/exec/obidos/ASIN/1861007701/ref=ase_electricporkchop" target="_blank" rel="nofollow">Professional SCWCD Certification</a><br />Co-author of <a href="http://www.amazon.com/exec/obidos/ASIN/186100561X/ref=ase_electricporkchop" target="_blank" rel="nofollow">Professional Java Servlets 2.3</a>
subject: Displaying alternative text when a tag's body is empty