Home

This Chapter
-Chapter 9: The Logic Tag Library
-The Value Comparison Tags
-The Substring Matching Tags
-The Presentation Location Tags
-The Collection Utility Tag
-Summary

Table of Contents
-Introduction
-Chapter 1: Model 2 and Struts
-Chapter 2: Input Validation with Action Forms
-Chapter 3: The HTML Tag Library
-Chapter 4: Input Validation and Data Conversion
-Chapter 5: The Validator Plugin
-Chapter 6: The Expression Language
-Chapter 7: JSTL
-Chapter 8: The Bean Tag Library
-Chapter 9: The Logic Tag Library
-Chapter 10: Struts-EL, Nested, selectLabel
-Chapter 11: Message Handling and Internationalization
-Chapter 12: The Tiles Framework
-Chapter 13: Securing Struts Applications
-Chapter 14: The Config Object
-Chapter 15: The Persistence Layer
-Chapter 16: Object Caching
-Chapter 17: File Upload and File Download
-Chapter 18: Paging and Sorting
-Chapter 19: Preventing Double Submits
-Chapter 20: Early HttpSession Invalidation
-Chapter 21: Decorating Request Objects
-Chapter 22: How Struts Works

Previous
Next

 

The Substring Matching Tags

Substring matching tags can be used to verify if a value is an exact match of the specified value, or if it starts or ends with the specified value. Table 9.2 lists the Logic Tag Library’s tags that fall into this category.

Tag Description JSTL Equivalent
match Executes the tag’s body if a value is an exact match of the specified value, or if it starts or ends with the specified value. c:if
notMatch Executes the tag’s body if a value is not an exact match of the specified value and if it does not start or end with the specified value. c:if

Table 9.2: The substring matching tags

The value to be compared can be a cookie, a request header, a request parameter, a scoped object, or a scoped object’s property. Just like the value comparison tags, you need the following attributes.

Additionally, you can use the scope attribute when using match or notMatch to compare the value of a scoped object or a scoped object’s property, to specify the scope of the scoped object. Its value may be one of the following: page, request, session, application, or any scope.

In addition, the match and notMatch tags have the optional location attribute that specifies how the string comparison should be performed. This attribute may have one of two possible values, start and end. If the value of this attribute is start, the comparison succeeds if the value tested starts with the specified value. If the value of location is end, the comparison evaluates to true if the value tested ends with the specified value. To test if a value is an exact match of a given value, the value of location can either be start or end. For example, consider the following match tag.

<logic:match parameter="category" value="classA" location="start">
  category starts with classA
</logic:match>

This tag tests if the value of the category request parameter starts with classA. The test evaluates to true if the category request parameter is classA, classAbc, etc. However, abcClass does not pass the test.

In the absence of the location attribute, the test succeeds if the tested value contains the prescribed value. For instance, the following match tag evaluates to true if the value of the category request parameter is classA, classAbc, abclassA, abclassAbc, and so forth.

<logic:match parameter="category" value="classA">
  category starts with classA
</logic:match>

If the value being compared does not exist, the match tag throws an exception. Therefore, you may want to use the present tag around this tag.

The notMatch tag does the opposite of the match tag. Here is an example of the notMatch tag.

<logic:notMatch parameter="category" value="classA location="start">
  category does not start with classA
</logic:notMatch>

Previous
Next