"How can I use a view object in forward only mode, and still detect if any rows were retrieved, without already iterating to the first row?"
When a view object is used in forward only mode, you can only iterate forward through the rows. Often, when building web applications it's useful to display something different in your page in the case when your query returns zero rows. For example, you might want to display a message like "Your search found no items..." instead of showing an HTML table with headers and no rows in the table. After calling executeQuery() on your view object, but before iterating through its resulting rowset, you can call the hasNext() method on the view object to detect whether there are any rows to iterate through without actually advancing to the first one. If hasNext() returns false, then you can conditionally display your nicer message. If you are building your application in a clean Model/View/Controller style, then this call to hasNext() on your datasource would be done in your controller code, and you would set some request-scope attribute that your view layer can use to detect for existence in order to conditionally display the "No items found" message. This latter approach is the technique that the BC4J Toy Store Demo application uses when showing the results of the users query through the store items.
11:47:11 PM
|
|