On Tue, 24 Apr 2001, Peter Alfors wrote:

> Hello all,
> 
> Sorry this is a bit off topic...    I posted this on the taglibs-user
> list but haven't had any luck.
> 
> How do you make an object available to the page as a script variable in
> a taglib without having to use a getAttribute() method to retrieve it?
> The jsp:useBean taglib allows you to specify the name of an object to
> retrieve from the desired scope.  From then on in the page, you can
> access this object using the specified id.
> 
> I have tried placing the object in the pageContext (using the PAGE,
> REQUEST, and APPLICATION scope)  However, you then need to
> do something like pageContext.getAttribute() to access it.
> 
> Any ideas on how jsp:useBean is getting around this???
> 

The <jsp:useBean> tag (and the <bean:define> tag as well) actually does
two things:
* It creates an attribute in whichever scope you tell it to.
* It defines a scripting variable that can be used (in scriptlets
  and runtime expressions) as a local variable.

In general, Struts based JSP pages tend not to use the scripting variable
approach, because nearly every Struts custom tag supports the "name" (and
optional "scope") attributes that access these beans for you.  In
application logic, though -- such as in an Action -- calling the
appropriate getAttribute() method is the only way to access these
attributes.  (The same is true when defining your own custom tags -- the
getAttribute() and findAttribute() methods in PageContext are very
commonly called.)

> Thanks,
>     Pete
> 
> 

Craig


Reply via email to