background image

Unified Expression Language

<< Creating Dynamic Content | JavaServer Faces Technology, >>
<< Creating Dynamic Content | JavaServer Faces Technology, >>

Unified Expression Language

Using Application-Specific Objects
When possible, application behavior should be encapsulated in objects so that page designers
can focus on presentation issues. Objects can be created by developers who are proficient in the
Java programming language and in accessing databases and other services. The main way to
create and use application-specific objects within a JSP page is to use JSP standard tags
(discussed in
"JavaBeans Components" on page 167
) to create JavaBeans components and set
their properties, and EL expressions to access their properties. You can also access JavaBeans
components and other objects in scripting elements, which are described in
Chapter 9,
"Scripting in JSP Pages."
Using Shared Objects
The conditions affecting concurrent access to shared objects (described in
"Controlling
Concurrent Access to Shared Resources" on page 106
) apply to objects accessed from JSP pages
that run as multithreaded servlets. You can use the following page directive to indicate how a
web container should dispatch multiple client requests:
<%@ page isThreadSafe=
"true|false" %>
When the isThreadSafe attribute is set to true, the web container can choose to dispatch
multiple concurrent client requests to the JSP page. This is the default setting. If using true, you
must ensure that you properly synchronize access to any shared objects defined at the page
level. This includes objects created within declarations, JavaBeans components with page scope,
and attributes of the page context object (see
"Implicit Objects" on page 162
).
If isThreadSafe is set to false, requests are dispatched one at a time in the order they were
received, and access to page-level objects does not have to be controlled. However, you still
must ensure that access is properly synchronized to attributes of the application or session
scope objects and to JavaBeans components with application or session scope. Furthermore, it
is not recommended to set isThreadSafe to false. The JSP page's generated servlet will
implement the javax.servlet.SingleThreadModel interface, and because the Servlet 2.4
specification deprecates SingleThreadModel, the generated servlet will contain deprecated
code.
Unified Expression Language
The primary new feature of JSP 2.1 is the unified expression language (unified EL), which
represents a union of the expression language offered by JSP 2.0 and the expression language
created for JavaServer Faces technology (see
Chapter 10, "JavaServer Faces Technology"
)
version 1.0.
The expression language introduced in JSP 2.0 allows page authors to use simple expressions to
dynamically read data from JavaBeans components. For example, the test attribute of the
following conditional tag is supplied with an EL expression that compares the number of items
in the session-scoped bean named cart with 0.
Unified Expression Language
The Java EE 5 Tutorial · September 2007
146