OverviewAssuming you have successfully obtained/built the Castor Taglib jar and configured your servlet container, you are ready to begin using the tags. The castor-taglib.jar needs to be in your WEB-INF/lib and the castor.tld needs to be in WEB-INF. At the top of each JSP that uses the library, you need to include the following. <%@ taglib uri='/WEB-INF/castor.tld' prefix='castor' %> Each of the tags is described in detail below. At a glance, the tags are:
jdoThis tag simply locates a Castor DataObjects instance from JNDI and makes it available as a paged scoped JDO object.
For example: <castor:jdo id="myJDO" jndiName="java:comp/env/jdo/CastorJdo" /> transactionThis tag begins and ends a Castor transaction. All other Castor tags must be nested within a Castor transaction tag. It implements the TryCatchFinally interface.
For example: <castor:transaction jdoName="myJDO"> <!-- other tags --> </castor:transaction> loadThis tag uses the Castor Database load method to obtain a data object from the database. If the object is not found, a new instance of the data object class is returned instead.
For example: <castor:transaction jdoName="myJDO"> <castor:load id="client" className="com.fc.example.data.ClientData" key="123" /> </castor:transaction> Or using EL to find the primary key from the request: <castor:transaction jdoName="myJDO"> <castor:load id="client" className="com.fc.example.data.ClientData" key="${param.clientId}" /> </castor:transaction> createThis tag uses the Castor Database create method to create a new data object in the database.
For example: <castor:transaction jdoName="myJDO"> <castor:create name="project" /> </castor:transaction> deleteThis tag uses the Castor Database remove() method to remove a data object in the database.
For example: <castor:transaction jdoName="myJDO"> <castor:delete name="project" /> </castor:transaction> updateThis tag uses the Castor Database update() method to create a data object that was loaded or queried in a different transaction. The data object must implement the Castor TimeStampable interface to support long transactions.
For example: <castor:transaction jdoName="myJDO"> <castor:update name="project" /> </castor:transaction> oqlThis tag retrieves an OqlQuery object from the Castor Database object. It must be nested within a transaction tag. It can have "bind" and "results" tags nested within it.
For example: <castor:oql query="SELECT p FROM com.fc.example.data.ClientData p"> <p>An example of a query with parameters (see "bind" below):</p> <castor:oql query="SELECT p FROM com.fc.example.data.ClientData p WHERE p.current=$1" > bindThis tag binds a parameter to an OqlQuery object. One or more must be nested within an oql tag where the query has parameters. The number of bind tags must match the number of query parameters.
For example: <castor:bind value="fred" /> Using an EL expression: <castor:bind value="${param.current}" /> resultsThis tag creates a QueryResults object by executing the oql query in the enclosing oql tag. It extends IterationTag.
For example: <castor:transaction jdoName="myJDO"> <castor:oql query="SELECT p FROM com.fc.example.data.ClientData p WHERE p.current=$1" > <castor:bind value="${param.current}" /> <castor:results id="result" page="${page}" size="${size}" indexId="index" accessMode="ReadOnly"> <c:out value="${result.id}"/> </castor:results> </castor:oql> </castor:transaction> |