logic


Standard Syntax:
     <%@ taglib prefix="logic" uri="http://struts.apache.org/tags-logic" %>

XML Syntax:
     <anyxmlelement xmlns:logic="http://struts.apache.org/tags-logic" />

Note: Some of the features in this taglib are also available in the JavaServer Pages Standard Tag Library (JSTL). The Struts team encourages the use of the standard tags over the Struts specific tags when possible.

This tag library contains tags that are useful in managing conditional generation of output text, looping over object collections for repetitive generation of output text, and application flow management.

For tags that do value comparisons (equal, greaterEqual, greaterThan, lessEqual, lessThan, notEqual), the following rules apply:

For tags that do substring matching (match, notMatch), the following rules apply:

Many of the tags in this tag library will throw a JspException at runtime when they are utilized incorrectly (such as when you specify an invalid combination of tag attributes). JSP allows you to declare an "error page" in the <%@ page %> directive. If you wish to process the actual exception that caused the problem, it is passed to the error page as a request attribute under key org.apache.struts.action.EXCEPTION.

Tag Library Information
Display NameNone
Version1.3
Short Namelogic
URIhttp://struts.apache.org/tags-logic
 

Tag Summary
empty

Evaluate the nested body content of this tag if the requested variable is either null or an empty string.

This tag evaluates its nested body content only if the specified value is either absent (i.e. null), an empty string (i.e. a java.lang.String with a length of zero), or an empty java.util.Collection or java.util.Map (tested by the .isEmpty() method on the respective interface).

JSTL: The equivalent JSTL tag is <c:if> using the empty operator. For example,
<c:if test="${empty sessionScope.myBean.myProperty}"> do something </c:if>

Since:
Struts 1.1
equal

Evaluate the nested body content of this tag if the requested variable is equal to the specified value.

Compares the variable specified by one of the selector attributes against the specified constant value. The nested body content of this tag is evaluated if the variable and value are equal.

forward

Forward control to the page specified by the specified ActionForward entry.

Performs a PageContext.forward() or HttpServletResponse.sendRedirect() call for the global ActionForward entry for the specified name. URL rewriting will occur automatically if a redirect is performed.

greaterEqual

Evaluate the nested body content of this tag if the requested variable is greater than or equal to the specified value.

Compares the variable specified by one of the selector attributes against the specified constant value. The nested body content of this tag is evaluated if the variable is greater than or equal to the value.

greaterThan

Evaluate the nested body content of this tag if the requested variable is greater than the specified value.

Compares the variable specified by one of the selector attributes against the specified constant value. The nested body content of this tag is evaluated if the variable is greater than the value.

iterate

Repeat the nested body content of this tag over a specified collection.

Repeats the nested body content of this tag once for every element of the specified collection, which must be an Iterator, a Collection, a Map (whose values are to be iterated over), or an array. The collection to be iterated over must be specified in one of the following ways:

  • As a runtime expression specified as the value of the collection attribute.
  • As a JSP bean specified by the name attribute.
  • As the property, specified by the property, of the JSP bean specified by the name attribute.

The collection to be iterated over MUST conform to one of the following requirements in order for iteration to be successful:

  • An array of Java objects or primitives.
  • An implementation of java.util.Collection, including ArrayList and Vector.
  • An implementation of java.util.Enumeration.
  • An implementation of java.util.Iterator.
  • An implementation of java.util.Map, including HashMap, Hashtable, and TreeMap. NOTE - See below for additional information about accessing Maps.

Normally, each object exposed by the iterate tag is an element of the underlying collection you are iterating over. However, if you iterate over a Map, the exposed object is of type Map.Entry that has two properties:

  • key - The key under which this item is stored in the underlying Map.
  • value - The value that corresponds to this key.

So, if you wish to iterate over the values of a Hashtable, you would implement code like the following:

<logic:iterate id="element" name="myhashtable">
Next element is <bean:write name="element" property="value"/>
</logic:iterate>

If the collection you are iterating over can contain null values, the loop will still be performed but no page scope attribute (named by the id attribute) will be created for that loop iteration. You can use the <logic:present> and <logic:notPresent> tags to test for this case.

lessEqual

Evaluate the nested body content of this tag if the requested variable is less than or equal to the specified value.

Compares the variable specified by one of the selector attributes against the specified constant value. The nested body content of this tag is evaluated if the variable is less than or equal to the value.

lessThan

Evaluate the nested body content of this tag if the requested variable is less than the specified value.

Compares the variable specified by one of the selector attributes against the specified constant value. The nested body content of this tag is evaluated if the variable is less than the value.

match

Evaluate the nested body content of this tag if the specified value is an appropriate substring of the requested variable.

Matches the variable specified by one of the selector attributes (as a String) against the specified constant value. If the value is a substring (appropriately limited by the location attribute), the nested body content of this tag is evaluated.

messagesNotPresent

Generate the nested body content of this tag if the specified message is not present in any scope.

Evaluates the nested body content of this tag if an ActionMessages object, ActionErrors object, a String, or a String array is not present in any scope. If such a bean is found, nothing will be rendered.

Since:
Struts 1.1
messagesPresent

Generate the nested body content of this tag if the specified message is present in any scope.

Evaluates the nested body content of this tag if an ActionMessages object, ActionErrors object, a String, or a String array is present in any scope. If such a bean is not found, nothing will be rendered.

Since:
Struts 1.1
notEmpty

Evaluate the nested body content of this tag if the requested variable is neither null, nor an empty string, nor an empty java.util.Collection (tested by the .isEmpty() method on the java.util.Collection interface).

This tag evaluates its nested body content only if the specified value is present (i.e. not null) and is not an empty string (i.e. a java.lang.String with a length of zero).

JSTL: The equivalent JSTL tag is <c:if> using the ! empty operator. For example,
<c:if test="${ ! empty sessionScope.myBean.myProperty}"> do something </c:if>

notEqual

Evaluate the nested body content of this tag if the requested variable is not equal to the specified value.

Compares the variable specified by one of the selector attributes against the specified constant value. The nested body content of this tag is evaluated if the variable and value are not equal.

notMatch

Evaluate the nested body content of this tag if the specified value is not an appropriate substring of the requested variable.

Matches the variable specified by one of the selector attributes (as a String) against the specified constant value. If the value is not a substring (appropriately limited by the location attribute), the nested body content of this tag is evaluated.

notPresent

Generate the nested body content of this tag if the specified value is not present in this request.

Depending on which attribute is specified, this tag checks the current request, and evaluates the nested body content of this tag only if the specified value is not present. Only one of the attributes may be used in one occurrence of this tag, unless you use the property attribute, in which case the name attribute is also required.

present

Generate the nested body content of this tag if the specified value is present in this request.

Depending on which attribute is specified, this tag checks the current request, and evaluates the nested body content of this tag only if the specified value is present. Only one of the attributes may be used in one occurrence of this tag, unless you use the property attribute, in which case the name attribute is also required.

redirect

Render an HTTP Redirect

Performs an HttpServletResponse.sendRedirect() call to the hyperlink specified by the attributes to this tag. URL rewriting will be applied automatically, to maintain session state in the absence of cookies.

The base URL for this redirect is calculated based on which of the following attributes you specify (you must specify exactly one of them):

  • forward - Use the value of this attribute as the name of a global ActionForward to be looked up, and use the module-relative or context-relative URI found there.
  • href - Use the value of this attribute unchanged.
  • page - Use the value of this attribute as an module-relative URI, and generate a server-relative URI by including the context path.

Normally, the redirect you specify with one of the attributes described in the previous paragraph will be left unchanged (other than URL rewriting if necessary). However, there are two ways you can append one or more dynamically defined query parameters to the hyperlink -- specify a single parameter with the paramId attribute (and its associated attributes to select the value), or specify the name (and optional property) attributes to select a java.util.Map bean that contains one or more parameter ids and corresponding values.

To specify a single parameter, use the paramId attribute to define the name of the request parameter to be submitted. To specify the corresponding value, use one of the following approaches:

  • Specify only the paramName attribute - The named JSP bean (optionally scoped by the value of the paramScope attribute) must identify a value that can be converted to a String.
  • Specify both the paramName and paramProperty attributes - The specified property getter method will be called on the JSP bean identified by the paramName (and optional paramScope) attributes, in order to select a value that can be converted to a String.

If you prefer to specify a java.util.Map that contains all of the request parameters to be added to the hyperlink, use one of the following techniques:

  • Specify only the name attribute - The named JSP bean (optionally scoped by the value of the scope attribute) must identify a java.util.Map containing the parameters.
  • Specify both name and property attributes - The specified property getter method will be called on the bean identified by the name (and optional scope) attributes, in order to return the java.util.Map containing the parameters.

As the Map is processed, the keys are assumed to be the names of query parameters to be appended to the hyperlink. The value associated with each key must be either a String or a String array representing the parameter value(s). If a String array is specified, more than one value for the same query parameter name will be created.

 


Java, JSP, and JavaServer Pages are trademarks or registered trademarks of Sun Microsystems, Inc. in the US and other countries. Copyright 2002-3 Sun Microsystems, Inc. 4150 Network Circle Santa Clara, CA 95054, U.S.A. All Rights Reserved.