org.josql.contrib
Class JoSQLJSPQueryTag

java.lang.Object
  extended by BodyTagSupport
      extended by org.josql.contrib.JoSQLJSPQueryTag

public class JoSQLJSPQueryTag
extends BodyTagSupport

Allows a JoSQL Query to be used in a JSP.

Example:

   <%@ page import="java.util.Arrays" %>
   <%@ page import="java.io.File" %>

   <%@ tablib prefix="josql" uri="josqltaglib" %>

   <josql:query inputList='<%= Arrays.asList (new File ("/home/me/").listFiles ()) %>'
                results="queryResults">
     SELECT *
     FROM   java.io.File
     WHERE  name = '.bashrc'
   </josql:query>
 

The body of the tag is taken as the statement to execute.

Note: this class deliberately does NOT extend Query since doing so would then prevent the query from being released via the release() method.

The following attributes are supported:


Constructor Summary
JoSQLJSPQueryTag()
           
 
Method Summary
 int doAfterBody()
          When called will parse the tag body into a JoSQL statement.
 int doEndTag()
          Execute the statement parsed in doAfterBody().
 void release()
          Release the objects we have references to and then call: super.release ().
 void setInputList(Object l)
          Set the input list, i.e.
 void setResults(String r)
          Set the name of the attribute that should hold the results.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JoSQLJSPQueryTag

public JoSQLJSPQueryTag()
Method Detail

setResults

public void setResults(String r)
Set the name of the attribute that should hold the results.

Parameters:
r - The name.

setInputList

public void setInputList(Object l)
Set the input list, i.e. the list of objects to execute the JoSQL statement against. Can be either a "java.lang.String" which will indicate the name of an attribute to use, or a "java.util.List" which will be the list of objects of use. The list of objects is not gained until the doEndTag() method is called.

Parameters:
l - The name or list of objects to execute the statement against.

doAfterBody

public int doAfterBody()
                throws JspException
When called will parse the tag body into a JoSQL statement.

Returns:
Tag#SKIP_BODY is returned.
Throws:
JspException - If the tag body cannot be parsed into a JoSQL statement.

doEndTag

public int doEndTag()
             throws JspException
Execute the statement parsed in doAfterBody(). The list of objects to execute the statement against is first retrieved using the value specified in setInputList(Object). The list must not be null and must be a list otherwise an exception is thrown.

Once executed the results are set as an attribute specified by: setResults(String).

Returns:
Tag#EVAL_PAGE always.
Throws:
JspException - If the list is null, not a list or the statement cannot be executed against the list of objects.

release

public void release()
Release the objects we have references to and then call: super.release ().



  Copyright © 2008 Gary Bentley. All Rights Reserved.