Web Tier to Go With Java EE 5: Summary of New Features in Java Standard Tag Library (JSTL) 1.2
2006-06-12 22:05
681 查看
|
By Pierre Delisle and Jennifer Ball, February 2006 |
First, JSTL is now part of the Java EE 5 platform. This means that you don't need to bundle JSTL with your web applications anymore. If you do have a copy of the JSTL library bundled with your application, the library provided by the container takes precedence.
Second, the goal of the maintenance review of JSTL was to support the alignment work done on the JavaServer Pages (JSP) and JavaServer Faces 1.2 specifications, which the previous article in this series discusses. This article provides an overview of how JSTL 1.2 contributes to the alignment of the web-tier technologies.
Alignment of JSTL Iteration Tags With JavaServer Faces Components
forEachtag did not work. For example, consider the following tag:
<c:forEach var="color" items="${colorList}"> <h:inputText value="#{color.name}"/> </c:forEach> |
coloris visible only within the boundaries of its iteration tag. This means that on a postback, the JavaServer Faces life cycle has no way to access the value associated with the variable
color.
To solve this issue, the JavaServer Faces input component needs the iteration variable to be a deferred expression that refers to the proper object within the collection over which the tag is iterating. One example of such an object might be
colorList[0]. With this solution, the deferred expression can be evaluated later on during the JavaServer Faces life cycle. Therefore, in JSTL 1.2, the
itemsattribute of the JSTL iteration tags now supports deferred expressions, as shown in the following example.
<c:forEach var="color" items="#{colorList}"> <h:inputText value="#{color.name}"/> </c:forEach> |
As background information, you may want to read the article "Unified Expression Language," which provides a detailed description of the unified EL. In version 1.2, JSTL now defines the attribute
itemsof
forEachand
forTokensso that they accept both runtime expressions and deferred-value expressions. A runtime expression can be specified using the
${}EL syntax, whereas a deferred-value expression is specified with the EL's
#{}syntax.
When a runtime expression is specified, it is evaluated immediately. For instance, in the example above,
${colorList}evaluates to a collection of
Colorobjects. However, when a deferred-value expression is specified for the
itemsattribute, the tag handler now adds a mapping for the
varattribute into an EL
VariableMapperinstance during each iteration.
The
VariableMapperinstance is one of the components that is provided to the EL API when an EL expression is created with the
ExpressionFactory.createValueExpression()API.
Let's take a look at a simplified version of the tag handler implementation of
forEachas it relates to the
VariableMapperinstance:
doStartTag() ... // If 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. // The index variable 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 that 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); ... |
itemsattribute changes between the rendering of the page and the postback of the page, undefined behavior will result.
The
setTag's Support for Deferred Values
setstandard action now also accepts deferred-value expressions. For example, consider this tag:
<c:setvar="d" value="#{handler.everythingDisabled}"/> ... <h:inputText id="i1" disabled="#{d}"/> <h:inputText id="i2" disabled="#{d}"/> |
varattribute into the EL
VariableMapperinstance.
Following is a simplified outline of how the tag handler for the
settag might process a deferred-value expression specified for the
valueattribute.
doStartTag() ... // If value is a deferred value, // get the current EL VariableMapper instance. VariableMapper vm = jspContext.getELContext().getVariableMapper(); // Assign the expression to the variable specified // in the var attribute so that any reference to // that variable will be replaced by the expression // in subsequent EL evaluations. vm.setVariable(getVar(), (ValueExpression)getValue()); ... |
相关文章推荐
- Web Tier to Go With Java EE 5: Summary of New Features in JavaServer Faces 1.2 Technology
- Web Tier to Go With Java EE 5: Summary of New Features in JSP 2.1 Technology
- Web Tier to Go With Java EE 5: A Look at Resource Injection
- How to properly logout of a Java EE 6 Web Application after logging in
- java.lang.ClassCastException: org.apache.taglibs.standard.tlv.JstlCoreTLV cannot be cast to javax.servlet.jsp.tagext.TagLibraryValidator
- JSTL(JavaServer Pages Standard Tag Library)初步
- HTTP Status 500 - The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
- The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this ap
- 使用spring 调试提示:Failed to load or instantiate TagLibraryValidator class: org.apache.taglibs.standard.tlv.JstlCoreTLV
- Java - How to change context root of a dynamic web project in eclipse
- Spark - ERROR Executor: Exception in tjava.lang.OutOfMemoryError: unable to create new native thread
- Failed to load or instantiate TagLibraryValidator class: org.apache.taglibs.standard.tlv.JstlFmtTLV
- This absolute uri http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
- Introduction to using Java Persistence API in a web application in Java EE environment
- JSP标准标签库 JSTL(JavaServer Pages Standard Tag Library)
- JSTL(Java Server Pages Standard Tag Library)标签函数库
- JasperException: Failed to load or instantiate TagLibraryValidator class: org.apache.taglibs.standard.tlv.JstlCoreTLV
- exception http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
- Take Advantage of ASP.NET Built-in Features to Fend Off Web Attacks
- The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application的解决办法