Java Reference
In-Depth Information
After dragging the JSTL If item to our page, NetBeans prompts us for
additional information.
The value of the Condition field must be enclosed in ${} ; this denotes this value as a
JSTL expression . In our particular example, we are looking for a request parameter
named displayConditionalText , whose value is true . If (and only if) the request
parameter is present and has the expected value, then the text inside the <c:if> tag
will be rendered in the generated HTML page from our JSP.
In the above screenshot, param is a JSTL implicit object to obtain the value of
a request parameter. param.displayConditionalText is equivalent to request.
getParameter("displayConditionalText") . As we can see, using the implicit
object allows us to save quite a bit of typing, and it makes our expression a lot more
readable. There are a lot of JSTL implicit objects, the most common ones are param ,
applicationScope , sessionScope , requestScope , and pageScope . Like we already
saw, param allows us to easily retrieve request parameters. The others in the list
allow us to retrieve attributes in the application, session, request, and page scopes,
respectively. They all use the dot notation we saw in the param implicit object, with
the key used to store the attribute following the dot, and return the object attached to
the appropriate scope with said key.
To see all implicit JSTL objects, simply invoke code completion
( Ctrl+Space ) between the two curly braces in a JSTL expression ( ${} ).
Back to our example, the Variable Name field is optional, if entered. It will be used
to store the value of the conditional expression in a Boolean variable. The Scope field,
is also optional. If a value is selected, this will be the scope of the variable entered
in the Variable Name field; if no value is selected for the Scope field, and a value is
entered for the Variable Name field, then the variable will have a default scope
of page.
 
Search WWH ::




Custom Search