On Thu, 7 Feb 2002, Lomvardias, Christopher wrote:

> Hi,
> 
> I'm just getting started working with some of the Jakarta Taglibs. One
> thing I'm interested in doing is something like this.
> 
> Let's say I've run a query and returned a result and want to place the
> value of a column into local variable. This obviously bombs.
> 
> How would I do this?

Not as such.  :-)

You have a few choices.  You can manually invoke the tag handler class and
call its methods (doStartTag(), doEndTag(), and so on), capturing its
output manually.  This is somewhat tedious and error prone, and I wouldn't
recommend it.  Alternatively, you can cause the tag to expose a scripting
variable -- that is, a variable accessible to scriptlet code.  The tag
needs to have this feature built in, however (by convention, using the
"id" attribute)  so that you can write code like this:

  <custom:tag id="foo" />
  <%= foo %>
  <% methodCall(foo); %>

DBTags's <sql:getColumn> tag, and the standard JSTL database tags, don't
support scripting variables; overall, scripting code (Java within JSP
pages) is being de-emphasized.  Instead, they expose outputs as scoped
variables that you can access with pageContext.findAttribute().  DBTags's
<sql:getColumn> has a "to" attribute that names the scoped attribute
exported:

  <sql:getColumn colName="fname" to="fname" />
  <%= pageContext.findAttribute("fname"); %>

The JSP Standard Tag Library (JSTL) introduces the convention of using an
attribute named 'var' to expose scoped variables, as

  <c:set var="foo">
     Foo!
  </c:set>

  // use 'foo' here

For more information on what replaces scripting variables and Java code
directly in JSP pages, you might be interested in an article I've recently
written on the subject.  You can get to it from the front page of Manning
Publications's web site at

   http://www.manning.com

Hope that helps explain things,

-- 
Shawn Bayern
Author, "JSP Standard Tag Library" (upcoming, Manning)  http://jstlbook.com


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to