Contents:
It is also recommended (at least in more complex applications) to
separete rendering pages
separate from equip logic, so that logic can be migrated into
(e.g.) Spring controllers later, while still being able to use the same
views. This
could be done in the interrim by the logic pages (with eq: tags) using
jsp:include or jsp:forward to link to separate view pages which share
data via request scoped variables.
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>where ${requestScope.matches} is the parameter called "matches" in the request scope(!)
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
...
<c:out value="${fn:length(requestScope.matches)}"/> objects<br>
<c:forEach var="match" items="${requestScope.matches}">
ID = <c:out value="${match.ID}"/>,
name=<c:out value="${match.name}"/><br>
</c:forEach>
...
The EQUIP2 custom taglib gives access to
(most of) the
normal equip2.core.ISession
API, plus support for creating equip2.core.QueryTemplate
objects. As noted above, this is only for
read access, and normally EQUIP2 update operations should go in custom
servlets/controllers
and/or application logic objects.
The recommended taglib prefix for the EQUIP2 taglib is 'eq'. The URI of the taglib
is
'http://www.mrl.nott.ac.uk/jsp/equip2'.
Use of the taglib is introduced within a JSP in the usual way:
...
<%@ taglib uri="http://www.mrl.nott.ac.uk/jsp/equip2" prefix="eq" %>
...
<%@ taglib uri="http://www.mrl.nott.ac.uk/jsp/equip2" prefix="eq" %>The session tag has the following (optional) attributes:
<eq:session> <!-- begins session -->
<!-- equip operation tags valid here... -->
</eq:session> <!-- ends session -->
Attribute name |
Required/ optional |
Type |
Default |
Meaning |
read_write |
optional |
boolean |
false |
Make the session type
READ_WRITE, rather than READ_ONLY, i.e. allow update operations. |
dataspacename |
optional |
String |
java:/app/env/provider/IDataspace |
Name to use to look up the
dataspace to use in the EQUIP2 naming Initial Context. |
dataspace |
optional |
equip2.core.IDataspace |
use dataspacename to locate
dataspace |
Direct reference to the
dataspace to use. |
... <!-- in a session... -->The eq:match tag has the following attributes (it must have an empty body):
<eq:match var="matches" template="${somevariable}"/>
...
Name |
Required/ optional |
type |
default |
Meaing |
var |
required |
String (not EL) |
- |
Name of variable to which
results should be bound. Results are of type Object[]. |
template |
required |
Object |
- |
Template object value (or equip2.core.QueryTemplate) to
be matched. |
scope |
optional |
one of page, request, session or application |
request |
Scope of declared variable, var. |
...Note that simple templates are always matched exactly; more complex queries (e.g. inequalities) can only be expressed using Query Templates, below.
<jsp:useBean id="mytemplate" class="mypackage.MyClass"/>
<jsp:setProperty name="mytemplate" property="name" value="Bob"/>
...
<eq:match var="matches" template="${mytemplate}"/>
...
The most flexibly way of expressing a match template is as an
instance of class equip2.core.QueryTemplate.
A number of tags support this.
The eq:query tag creates a Query Template and binds it to a scoped
variable:
<eq:query var="qt" classname="mypackage.MyClass">The eq:query tag has the following attributes:
<!-- constraints and order specified here... -->
</eq:query>
Name |
required/ optional |
type |
default |
Meaning |
var |
required |
String (not EL) |
- |
Name of variable to bind
resulting query template to. |
scope |
optional |
one of page, request, session or application | request |
Scope of declared variable, var. |
classname |
required |
String |
- |
Name of java class to match |
maxResults |
optonal |
int |
0 (unlimited) |
Maximum numbers of matching
objects to return. |
firstResult |
optional |
int |
0 |
Index (counting from 0) of first
object to return, i.e. discard this many results first. |
The body of the eq:query
tag can include eq:constraint
and eq:order tags to
further specify the query.
Each eq:constraint tag
specifies a value constraint on a single property of the query's class.
For example, the equivalent of the simple template before (fixed name
'Bob') would be:
<eq:query var="qt" class="mypackage.MyClass">
<eq:constraint property="name" constraint="eq" value="Bob"/>
</eq:query>
Note that it is normally clearer to use one of the specialised
constraint tags (in this case eq:constraint-eq)
described below, rather than the generic constraint tag.
The eq:constraint tag
has the following attributes:
Name |
required/ optional |
type |
default |
Meaing |
property |
required |
String |
- |
Name of the property to be
constrained |
constraint |
required |
one of eq, ne, lt, gt, le, ge, isnull,
notnull, like, in, notin |
- |
Kind of constraint (equal, not
equal, less than, greater than, less than or equal, greater than or
equal, is null, not null, like (SQL pattern match)) |
value |
optional |
Object |
null |
Value for comparison with
property (for all constraints except isnull/notnull). |
The following specialised constraint tags are also specified, each
for one particular constraint type:
Tag name |
eq:constraint constraint |
Value required? |
Property constraint |
constraint-eq |
eq |
yes |
equals value |
constraint-ne |
ne |
yes |
not equal to value |
constraint-gt |
gt |
yes |
greater than value |
constraint-lt | lt |
yes | less than value |
constraint-ge | ge |
yes | greater than or equal to value |
constraint-le | le |
yes | less than or equal to value |
constraint-isnull | isnull |
no |
is null |
constraint-notnull | notnull |
no |
is not null |
constraint-like | like |
yes | matches value, using SQL 'like'
syntax, i.e. '%' matches any 0 or more characters; '_' matches any one
character. |
constraint-in |
in |
yes |
in, i.e. equals one of the array
of values provided (array type castable to Object[]) |
constraint-notin |
in |
yes |
not in, i.e. not equal to any of
the array of values provided (array type castable to Object[]) |
It is important for matching that the Java type of the value
corresponds to the Java type of the property being tested against. This
can be hard to achieve using JSP Expression Language, and JSP
expressions or scriptlets may be required instead. For example, a
default EL number ("${0}") is actually a Long. Some examples of
particular primitive type values are given below:
The eq:order tag has
the following attributes:
Name |
required/ optional |
type |
default |
Meaing |
property |
required |
String |
- |
Name of the property for results to be sorted by |
descending |
optional |
boolean |
false |
sort in descending rather than
ascending order |
<eq:matchUnique var="VARNAME" [scope="page|request|session|application"]
template="TEMPLATEVALUE"/> <%-- result type Object --%>
The API get operation
is provided by the eq:get
tag. This retrieves a single Object
(if it is present, else null) by matching its class and identity.
Identity, if defined for that class, is typically one of its
properties.
For example:
<eq:get var="VARNAME" [scope="page|request|session|application"]
classname="CLASSNAME" identity="IDENTITYVALUE"/> <%-- result type CLASSNAME --%>
The API count operation is provided by the eq:count tag. This
returns the count of the number of objects satisfying a match with the
given template. For example:
<eq:count var="VARNAME" [scope="page|request|session|application"]
template="TEMPLATEVALUE"/> <%-- result type Integer --%>
<eq:add object="VALUE"/>
<eq:remove object="VALUE"/>
<eq:update object="VALUE"/>
<eq:addOrUpdate object="VALUE"/>
Refer to the EQUIP2 API
documentation for more information on these operations and
modifying the dataspace.
The built taglib is the jar dist/equip2taglib.jar,
and is built by the ant
target 'taglib'. Building
requires the servlet and jsp API jars; the current build assumes you
have a local Tomcat install in which they can be found.
The source is under src/equip2/taglib/j2se.
The taglib desriptor file is etc/eq.tld.