FileDocCategorySizeDatePackage
ConditionalTagSupport.javaAPI DocGlassfish v2 API6298Sat May 05 19:17:14 BST 2007javax.servlet.jsp.jstl.core

ConditionalTagSupport

public abstract class ConditionalTagSupport extends javax.servlet.jsp.tagext.TagSupport

Abstract class that facilitates implementation of conditional actions where the boolean result is exposed as a JSP scoped variable. The boolean result may then be used as the test condition in a <c:when> action.

This base class provides support for:

  • Conditional processing of the action's body based on the returned value of the abstract method condition().
  • Storing the result of condition() as a Boolean object into a JSP scoped variable identified by attributes var and scope.
author
Shawn Bayern

Fields Summary
private boolean
result
private String
var
private int
scope
Constructors Summary
public ConditionalTagSupport()
Base constructor to initialize local state. As with TagSupport, subclasses should not implement constructors with arguments, and no-argument constructors implemented by subclasses must call the superclass constructor.

        super();
        init();
    
Methods Summary
protected abstract booleancondition()

Subclasses implement this method to compute the boolean result of the conditional action. This method is invoked once per tag invocation by doStartTag().

return
a boolean representing the condition that a particular subclass uses to drive its conditional logic.

public intdoStartTag()
Includes its body if condition() evaluates to true.


        // execute our condition() method once per invocation
        result = condition();

        // expose variables if appropriate
        exposeVariables();

        // handle conditional behavior
        if (result)
            return EVAL_BODY_INCLUDE;
        else
            return SKIP_BODY;
    
private voidexposeVariables()

        if (var != null)
            pageContext.setAttribute(var, Boolean.valueOf(result), scope);
    
private voidinit()

        result = false;                 // not really necessary
	var = null;
	scope = PageContext.PAGE_SCOPE;
    
public voidrelease()
Releases any resources this ConditionalTagSupport may have (or inherit).

        super.release();
        init();
    
public voidsetScope(java.lang.String scope)
Sets the 'scope' attribute.

param
scope Scope of the 'var' attribute

	if (scope.equalsIgnoreCase("page"))
	    this.scope = PageContext.PAGE_SCOPE;
	else if (scope.equalsIgnoreCase("request"))
	    this.scope = PageContext.REQUEST_SCOPE;
	else if (scope.equalsIgnoreCase("session"))
	    this.scope = PageContext.SESSION_SCOPE;
	else if (scope.equalsIgnoreCase("application"))
	    this.scope = PageContext.APPLICATION_SCOPE;
	// TODO: Add error handling?  Needs direction from spec.
    
public voidsetVar(java.lang.String var)
Sets the 'var' attribute.

param
var Name of the exported scoped variable storing the result of condition().

	this.var = var;