dsp:getvalueof lets you save a JavaBean component, Page parameter, or Static value to an attribute in the specified scope. Other tags such as dsp:valueof
can then reference that value. The attribute is also accessible to the JSP Expression Language (EL).
dsp:getvalueof
has the following syntax:
<dsp:getvalueofsource-value
var="var-name
" [scope="scope-spec
"] ] > </getvalueof>
where source-value
specifies the value sources as a JavaBean component, Page parameter, or Static value:
bean="
nucleus-path/c
omponent
-name
"
param="
param-name
"
value="
static-value
"
JavaBean component
dsp:getvalueof
can make JavaBean components available to EL. The following dsp:getvalueof
tag sets the attribute student
to reference the Nucleus component /atg/samples/Student_01
. The tag omits a scope
specification, so the default pageScope
is applied:
<dsp:getvalueof bean="/atg/samples/Student_01" var="student"></dsp:getvalueof>
The attribute student
provides access on the current JSP to all Student_01
component properties. For example, you can use EL to render this component’s age
property:
You are <c:out value="${student.age}"/> years old.
Page parameter
dsp:getvalueof
can make page parameters available to EL. For example, given the page parameter sex
, dsp:getvalueof
can set the requestScope
attribute gender
to reference that parameter:
<dsp:getvalueof param="sex" var="gender" scope="request"> </dsp:getvalueof>
After you set this attribute, it is accessible to other objects in the same request scope. In the following example, the c:when
tag evaluates requestScope.gender
in order to determine which content to display:
<c:choose> <c:when test="${gender == "female"}"/> Formal dresses are on sale! </c:when> <c:when test="${gender == "male"}"> Tuxedos are on sale! <c:when> </c:choose>
Static value
dsp:getvalueof
can save a static value to an EL variable, as in the following example:
<dsp:getvalueof value="student" var="userType"> </dsp:getvalueof>
Subsequent references to the userType
attribute resolve to the literal string student
.