[ Team LiB ] Previous Section Next Section

Tag Libraries Shipped with WebLogic Server

The tag libraries shipped with WebLogic Server are weblogic-tags.jar (referred to as WebLogic custom tags) and weblogic-vtags.jar (referred to as WebLogic validation tags). These libraries are included within your distribution. They're located within the BEAHome\WebLogicHome\server\ext directory. The JARs provided contain implementation classes along with tag library descriptors (TLDs).

WebLogic Custom Tags

The WebLogic custom tags library (weblogic-tags.jar) contains classes that assist in the caching and processing of data. The three custom tags are cache, repeat, and process.

The Cache Tag

The cache tag enables work done within the body of the cache tag to be cached. Body content may be cached before or after processing. This construct enables the developer to modify JSP page variables or further process tag body content prior to final output. The cache tag includes attributes for refresh and flush procedures. An example using the cache tag is provided here:

<wl:cache name="auctionDbTable" key="accontNumber" scope="session">
<--read account data into cache-->
The Repeat Tag

The repeat tag allows iteration over several different types of sets (enumerations, iterators, collections, arrays of objects, vectors, result sets, result set metadata, and hash table keys). The repeat tag provides a count attribute to implement simple loops. An example that uses the repeat tag is provided here:

<wl:repeat id="currentAuctionItems" set="<%=catalogue.getItems()%>"> <--method getItems()
graphics/ccc.gif returns a String-->
 <%=currentAuctionItems%> <--prints each item-->
The Process Tag

The process tag allows query parameter–based processing. This tag enables selective processing based on a name-value-Boolean scheme; that is name, not-name, value, not-value. Here's an example that uses the process tag:

<wl:process notname="update"
<!--Only show if there is no update -->
 <form action="post">
  <input type="text" name="accountNumber"/>
  <input type="submit" name="update" value="Update"/>

<wl:process name="Update">
 <!--do the update -->

For detailed information about the specifics of these WebLogic custom tags and their attributes, refer to the BEA documentation site at http://edocs.beasys.com/wls/docs81/jsp/customtags.html.

WebLogic Validation Tags

The WebLogic validation tags library (weblogic-vtags.jar) contains classes and a tag library descriptor for three custom tags that, working in unison, implement HTML form user entry validation. The validation schemes issues a warning if required entries are omitted. Additionally, two versions of text comparisons are implemented: text comparison versus a sibling form field (as with password entry confirmations), and text comparison against an existing or regular expression. A framework for custom validation support is also provided. These tags are summary, form, and validation.

The Summary Tag

The WebLogic summary tag is the top-level validation tag. The validation tag signals the head and tail of the validation construct. The head summary tag defines the name of an error message vector (logs each error message activated), a general error text message, and a redirect page for successful data entry. The error vector and the text message are usually dereferenced using JSP tags. If errors are encountered, the page is redrawn displaying the errant fields. WebLogic summary tag syntax is shown here:

<prefix:summary name="errorVector" headerText="General Page Error Message"
graphics/ccc.gif redirectPage="allEntriesValid.jsp">
...form body...> (Note: HTML may be used within form body)
The Form Tag

Similar to HMTL forms, the WebLogic Form tag defines the physical form. Fields and WebLogic validation tags are defined within the WebLogic form tag. One or more forms may be colocated within one set of summary tags. As with HTML forms, the form tag defines the method and action parameters of the form, along with field name-value pairs. WebLogic form tag syntax is shown here:

<prefix:form method="GET"|"PUT" action="allEntriesValid.jsp"/>
<--Fields /Field Validations Defined Here-->
<input type="text" name="field" >
<input type="submit" value="Button Label">
The Validation Tag

WebLogic validation tags validates each form field for allowable entries. Validations are implemented via three utility classes: RequiredFieldValidator (validates whether a required field is populated), RegExpValidator (validates whether a field is equal to a target expression), and CompareValidator (validates by comparing one field within the form to another). WebLogic also provides the CustomizableAdapter class that allows for user-defined validation. Form fields may have one or more validation tags. WebLogic form validation syntax is shown in the following snippet:

<prefix:form method="GET"|"PUT" action="allEntriesValid.jsp"/>
<--Fields /Field Validations Defined Here-->
<input type="text" name="fieldA" >
<prefix:validator fieldToValidate="fieldA"
errorMessage="Field Specific Error Message"
<img src="image.gif">Field Specific Error Message
<input type="submit" value="Button Label">

For detailed information about WebLogic validation tags, including attributes and use, refer to the BEA documentation site at http://edocs.beasys.com/wls/docs81/jsp/customtags.html.

Using the WebLogic Server Tag Library

To use the WebLogic Server tag libraries, copy the weblogic-tags.jar file to the WEB-INF/lib directory of the application containing your JSP pages. Add the tag library's uri to your application's web.xml file as shown here:


Finally, you must reference the library within your JSP page as shown:

<%@ taglib uri="weblogic-tags.tld" prefix="wl" %>

The WebLogic tag Library is now available for use within your JSP page.

Example Using WebLogic Validation Tag Library

Let's work through an example using WebLogic validation tags. In Listing 17.1, bidSubmission.jsp, we've implemented a WebLogic JSP validation tag to validate bid requests. Note the custom tag directive in line 2 and the validation declaration in line 4, which includes the redirect success page, goodBid.jsp. The JSP takes a HTTP request, which contains a bid item in lines 13–18. Line 22 begins the physical layout of the form with the declarations of the form tag. Lines 25–30 are where we implement our error notice. Notice the HTML tags interspersed throughout the logic.

Listing 17.1 BidSubmission.jsp
1 <%@ page import="com.gams.ejbs.item.*, java.sql.Date" %>
+2 <%@ taglib uri="weblogicv.tld" prefix="wl" %>
4 <wl:summary name="errorVector" headerText="<font color=red>Oooops!</font>"
graphics/ccc.gif redirectpage="goodBid.jsp" >
6 <html>
7 <head>
8   <title>Global Auctions - Bid Submission</title>
9 </head>
10 <body>
11 <h1>Global Auctions - Bid Submission</h1>
13 <% ItemValue iv;
14  if (null != request.getAttribute("item")) {
15    iv = (ItemValue)request.getAttribute("item");
16  }
17  else {
18    iv = new ItemValue(new Integer(101), "Ming Chair", new Float(550.50), new java.sql
graphics/ccc.gif.Date(102, 06, 30));
19  }
20  session.setAttribute("item",iv);
21 %>
22  <wl:form method="GET" action="goodBid.jsp" >
23  <table>
24 <%
25  if ( errorVector.size() > 0 ) {
26    out.println("<tr><td><h2>" + headerText + "</h2></td></tr>");
27    out.println("<tr><td><b>Just A Reminder:</b></td></tr>");
29    for ( int i = 0; i < errorVector.size(); i++ ) {
30      out.println("<tr><td><font color=red>" + (String)errorVector.elementAt(i)+ "</font><
31    }
32  }
33 %>
34  <tr><td>Item Number:</td><td><%=iv.getItemId()%></td></tr>
35  <tr><td>Description:</td><td><%=iv.getTitle()%></td></tr>
36  <tr><td>Bid Close Date: </td><td><%=iv.getEndDateTime()%></td></tr>
37  <tr><td>Current Bid: </td><td><%=iv.getCurrentBid()%></td></tr>
39  <tr><td>Bidder ID: </td><td><input type="text" name="bidderId" ></td></tr>
40  <wl:validator fieldToValidate="bidderId"
41       validatorClass="weblogicx.jsp.tags.validators.RequiredFieldValidator"
42       errorMessage="Don't Forget Your Bidder ID Number!">
43  <tr><td colspan="2"><font color="red">ID Number is Required!!!</font></td></tr>
44  </wl:validator>
46  <tr><td>Bid (per item): </td><td><input type="text" name="bid" ></td></tr>
47  <wl:validator fieldToValidate="bid"
48      validatorClass="weblogicx.jsp.tags.validators.RequiredFieldValidator"
49      errorMessage="How Much Do You Really Want to Bid?">
50  <tr><td colspan="2"><font color="red">Invalid Bid!!!</font></td></tr>
51  </wl:validator>
52  <wl:validator fieldToValidate="bid"
53      validatorClass="com.gams.util.NonZeroValidator"
54      errorMessage="Is That How Much You Really Want To Bid?">
55  <tr><td colspan="2"><font color="red">Invalid Bid!!!</font></td></tr>
56  </wl:validator>
58  <tr><td>Quantity(Requested): </td><td><input type="text" name="quantity" > </td></tr>
59  <wl:validator fieldToValidate="quantity"
60      validatorClass="weblogicx.jsp.tags.validators.RequiredFieldValidator"
61      errorMessage="How Many Do You Really Want?">
62  <tr><td colspan="2"><font color="red">Invalid Quantity!!!</font></td></tr>
63  </wl:validator>
64  <wl:validator fieldToValidate="bid"
65      validatorClass="com.gams.util.NonZeroValidator"
66      errorMessage="Is That How Many You Really Want?">
67  <tr><td colspan="2"><font color="red">Invalid Quantiy!!!</font></td></tr>
68  </wl:validator>
70  <input type="submit" value="Submit Form">
72  </table>
73  </wl:form>
74  </wl:summary>
75 </body>
76 </html>

In line 39, note the first field definition, followed by a validation block beginning in line 40. From lines 40–68 form fields are implemented and complemented by validations. Notice the custom validation class in line 65. At line 68, we close the final validation, followed by a form submit button definition in line 70. Note how the button is defined after the last validation, but before the form end tag that occurs in line 73. The validation is closed by the summary end tag in line 74. Listing 17.1 yields the output displayed in Figures 17.117.3.

Figure 17.1. BidSubmission.jsp, initial state.


Figure 17.3. Unsuccessful Bid, BidSubmission.jsp.


The success page, goodBid.jsp, is displayed in Figure 17.2.

Figure 17.2. Successful Bid, GoodBid.jsp.


The validation error notices, also goodBid.jsp, is displayed in Figure 17.3.

    [ Team LiB ] Previous Section Next Section