jutil Tag Library Documentation
Library Version: 1.0 A library of JSP utility tags.
Library Description
A library of JSP utility tags. It has tags controlling basic page logic. Tag Details<jutil:use> Tag
Tag Handler Class:
This tag is used to load object data from a controller. These objects are defined as properties of the controller. Consult the documentation for individual controllers to determine the properties available in that controller. The <jutil:use var="order" controller="Cart" /> <jutil:use var="order" controller="Cart" property="order" /> The JSP page may need some request parameters to properly retrieve
object data from the controller. For example, suppose the following tag
appeared in the showItem.jsp page using the <jutil:use var="item" controller="Catalog" /> public class CatalogController extends Controller { public Item getItem(Long itemId) throws Exception { return Item.load(itemId); } // Other methods ... } To load the item object, the URL would need to pass the item id value of
the item being retrieved, e.g.
Technical Note: The required parameters will be determined
by the initializer/getter method for the controller in question.
For more information, see the documentation for the Tag Attributes
<jutil:new> Tag
Tag Handler Class:
This tag is used to create brand new objects. It is useful for creating page helper objects that are not associated with any given controller or new objects for forms. <jutil:new var="item" type="com.domain.catalog.Item" /> <h1>Create Catalog Item</h1> <jhtml:form action="Catalog.createItem.cmd"> <table> <jhtml:field property="name" /> <jhtml:field property="stock" /> <jhtml:field property="price" /> <jhtml:field property="startDate" /> <tr> <td> </td> <td><input type="submit" value="Submit"></td> </tr> </table> </jhtml:form> Technical Note: The new business object created by this tag is simply a dummy object, used only for form generation. Its values should not be manipulated by this page. Tag Attributes
<jutil:set> Tag
Tag Handler Class:
This tag gets a subordinate object out of another object and stores the subordinate object in a page variable. A subordinate object is one that is stored in a property of its owner. Consult an object's documentation to determine which subordinate objects it contains. The example below gets the <jutil:use var="order" controller="Cart" /> <jutil:set var="lineItems" object="order" /> Alternately, this tag can use a JSTL Expression Language statement to define a value. For example, so store the "preview" request parameter in an "isPreview" variable: <jutil:set var="isPreview" el="${param.preview}" /> Technical Note: This tag uses the appropriate getter method to retrieve the subordinate object. Tag Attributes
<jutil:print> Tag
Tag Handler Class:
This tag prints object information. The example below prints the
<jutil:use var="item" controller="Catalog" /> <jutil:print object="item" property="name" /> The Object value: <jutil:print object="item" /> Object property value: <jutil:print object="item" property="price" /> Property attribute value: <jutil:print object="item" property="price" attribute="label" /> If no property is specified, the value of the object itself is printed instead. If a property attribute is specified, the attribute value is printed. If no object is specified, the default object is used. Alternately, the print value can be expressed using a JSTL Expression Language statement: <jutil:print el="{$param.redirect}" /> The information is not necessarily displayed to the user. For example, this tag can be used to insert parameter values into URLs: <jutil:use var="item" controller="Catalog" /> <a href="showItem.jsp?itemId=<jutil:print property='itemId' />"> Show Item </a> If a datatype is specified, the tag attempts to print the value as the specified datatype rather than its normal datatype: <jutil:print object="item" property="startDate" datatype="LongDate" />
Technical Note: This tag uses the appropriate getter method
to retrieve the property value. If no property is specified, it uses
the object's Tag Attributes
<jutil:forEach> Tag
Tag Handler Class:
This tag is used for looping through a collection of objects, so their values can be printed one-by-one. It is often used to generate HTML tables from object data. <jutil:use var="itemList" controller="Catalog" /> <table> <jutil:forEach var="item" collection="itemList"> <tr> <td><jutil:print property="itemId" /></td> <td><jutil:print property="name" /></td> <td><jutil:print property="stock" /></td> </tr> </jutil:forEach> </table> For example, if the The During iteration, the current iteration count is stored in a variable
named
Technical notes: Legitimate collections include arrays
of objects, Also note that this tag has no facilities for looping through
a subset of a collection (as is the case in JSTL). This is because
this kind of logic is better handled in the controller layer. To
display a subset of a collection, define a controller method that
derives the correct subset and returns a collection containing that
subset to the JSP via a Tag Attributes
<jutil:printError> Tag
Tag Handler Class:
This tag checks for the existence of an error (or exception) and prints out its message. If there is no error, this tag prints nothing. <%@ page isErrorPage="true" %> <p><b><font color="red"><jutil:printError /></font></b></p> Optionally, you may specify a <table> ... <tr colspan="2"><td> <font color="red"><jutil:printError parameter="name" /></font> </td></tr> <tr> <td><jhtml:label property="name" /></td> <td><jhtml:input property="name" /></td> </tr> ... </table>
Technical Note: This tag searches the standard request
attribute for the exception, which is compatible with the JSP standard
for error pages. This attribute's name is defined in the constant
Tag Attributes
<jutil:if> Tag
Tag Handler Class:
This tag evaluates an object property as a conditional (boolean) value: <jutil:use var="items" controller="Cart" /> <jutil:if object="items" property="empty"> <p><font color="red">No items in cart.</font></p> </jutil:if> If the property evaluates to a value of If the property is omitted, the object itself is evaluated as a boolean condition value. Alternately, you can define the condition using a JSTL expression language value: <jutil:if el="{$param.preview}"> Show preview ... </jutil:if> Tag Attributes
<jutil:else> Tag
Tag Handler Class:
This tag works in conjunction with the <jutil:use var="items" controller="Cart" /> <jutil:if object="items" property="empty"> <p><font color="red">No items in cart.</font></p> </jutil:if> <jutil:else> [Print out cart contents] </jutil:else> If the preceding <jutil:use var="items" controller="Cart" /> <jutil:if object="items" property="empty"> <p><font color="red">No items in cart.</font></p> <jutil:else> [THIS WILL NOT WORK] </jutil:else> </jutil:if> <jutil:elseIf> Tag
Tag Handler Class:
This tag is effectively a combination of an "else" and an "if" tag. Its
contents will be executed provided that (a) the previous Tag Attributes
<jutil:param> Tag
Tag Handler Class:
This tag specifies parameter values for parametrized tags. The
Tag Attributes
<jutil:element> Tag
Tag Handler Class:
This tag specifies the span of a page element. It is used in conjunction
with the <a href="showItem?id=<jutil:print object="item" property="itemId"/>"> Go to item <jutil:print object="item" property="itemId"/> </a> This can be replaced by the verbose but well-formed: <jutil:element name="a"> <jutil:attribute name="href"> showItem?id=<jutil:print object="item" property="itemId"/> </jutil:attribute> Go to item <jutil:print object="item" property="itemId"/> </jutil:element> The output is: <a href="showItem?id=###">Go to item ###</a> Here " Tag Attributes
<jutil:attribute> Tag
Tag Handler Class:
This tag generates an attribute for a
Unlike the <jutil:element name="input"> <jutil:if object="question" property="multipleCorrectAnswers"> <jutil:attribute name="type">checkbox</jutil:attribute> </jutil:if> <jutil:else> <jutil:attribute name="type">radio</jutil:attribute> </jutil:else> <jutil:if object="answer" property="selected"> <jutil:attribute name="checked">checked</jutil:attribute> </jutil:if> <jutil:attribute name="name">answerId</jutil:attribute> <jutil:attribute name="value" object="answer" property="id" /> </jutil:element> Tag Attributes
|