JSR 052 • JavaServer Pages™ (JSP™) Standard Tag Library (JSTL)
Maintenance Review 2 (JSTL 1.2)

Description

Second maintenance review of the JavaServer Pages™ (JSP™) Standard Tag Library (JSTL 1.2).

Maintenance Lead

Pierre Delisle, Sun Microsystems, Inc.

Feedback

Comments should be sent to jsr-52-comments@jcp.org

Rationale for proposed changes

The goal of this maintenance release is to align the JSTL specification with the work done on the JavaServer Pages 2.1 and JavaServer Faces (Faces) 1.2 specifications. Also, as of this release (JSTL 1.2), JSTL is now part of the Java Enterprise Edition platform.

Proposed Changes

1. Iteration tags support for nested actions with deferred-values referring to the iteration variable

The semantics of the standard actions <c:forEach> and <c:forTokens> are modified to allow the iteration tags to work seamlessly with nested JavaServer Faces actions.

More specifically, <c:forEach> and <c:forTokens> now support nested actions with deferred-values referring to the iteration variable, as long as a deferred value has been specified for the 'items' attribute.

For example:

  <c:forEach var="item" items="#{model.list}">
    <h:inputText value="#{item.name}"/>
  </c:forEach>
Changes: Below are some implementation notes illustrating how an iteration tag handler may process a deferred-value specified for the 'items' attribute.
  doStartTag()
     ...
     // 'items' is a deferred-value
     // Get the current EL VariableMapper
     VariableMapper vm = jspContext.getELContext().getVariableMapper();

     // Create an expression to be assigned to the variable specified
     // in the 'var' attribute.
     // 'index' is an iteration counter kept by the tag handler.
     myimpl.IndexedExpression expr = new myimpl.IndexExpression(getItems(), index);

     // Assign the expression to the variable specified in the 'var' attribute,
     // so any reference to that variable will be replaced by the expression 
     // in subsequent EL evaluations.
     oldMapping = vm.setVariable(getVar(), expr);
     ...


   doEndTag() 
     ...
     // restore the original state of the VariableMapper:
     jspContext.getELContext().getVariableMapper().setVariable(getVar(), oldMapping);
     ...

The number of items referred to by the "items" attribute must be the same when JSF creates the component tree and when JSP executes the iteration tag. Undefined behavior will result if this is not the case.

2. <c:set> support for deferred values

The semantics of the standard action <c:set> have been modified to allow the action to accept a deferred-value.

For example:
  <c:set var="d" value="#{handler.everythingDisabled}"/>
  ...
  <h:inputText id="i1" disabled="#{d}"/>
  <h:inputText id="i2" disabled="#{d}"/>
Changes: Below are some implementation notes illustrating how the <c:set> tag handler may process a deferred-value specified for the "value" attribute.
   doStartTag()
     ...
     // 'value' is a deferred-value
     // Get the current EL VariableMapper
     VariableMapper vm = jspContext.getELContext().getVariableMapper();

     // Assign the expression to the variable specified in the 'var' attribute,
     // so any reference to that variable will be replaced by the expression 
     // in subsequent EL evaluations.
     vm.setVariable(getVar(), (ValueExpression)getValue());
     ...

3. Generics

4. Minor corrections