It's not a secret anymore!
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes @Variable Directive Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "@Variable Directive" Watch "@Variable Directive" New topic

@Variable Directive

Sunder Ganapathy
Ranch Hand

Joined: Apr 01, 2003
Posts: 120
I have tried to see the working of Variable directive in Tag Files.

The expression ${x} does not get evaluated. Why?

Tag File : ( Header.Tag )

<%@ variable name-given="x" scope="AT_END" %>
<c:set var="x" value="5" />

<%@ attribute name="subTitle" required="true" rtexprvalue="true" %>

<img src="GTITLE.gif"> <br>
<h1>Hi, </h1>
<em><strong>${subTitle}</strong></em> <br>

JSP File : ( Header.JSP)

<%@ taglib prefix="myTags" tagdir="/WEB-INF/tags" %>

<title>Header Tags Example</title>

<body bgcolor="#660099">
<h3>Simple Header Tag</h3>


<myTags:Header subTitle="We take the Sting out of SOAP" >

<c ut value="${x}" />
Welcome to our site.


Actually in the source I could see the value of x being set to 5.
But, the expression of ${x} is not evaluated.
I tried all three properties, AT_END, AT_BEGIN & NESTED.
Shivani Chandna
Ranch Hand

Joined: Sep 18, 2004
Posts: 380
Hello Sunder,

When you specify :

Means x is a variable whose value will be going out from the tag to the calling jsp file. Its an OUT (or like a return type variable)....

In the Tag file you can modify the value.

Doing so would allow the ~~return value to be synchronized depending on the scope specified.

Also note, that the OUT variables do not get initialized with the values specified in the calling jsp files - but are only capable of setting values in these variable - that are to be returned.

Note: I do hope that you are importing the Jstl core library in the tag file so that c:set works correctly?.

[ July 25, 2006: Message edited by: Shivani Chandna ]

/** Code speaks louder than words */
I agree. Here's the link:
subject: @Variable Directive
jQuery in Action, 3rd edition