tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hans Bergsten <h...@gefionsoftware.com>
Subject Re: <c:set> vs. <bean:define> and <%= %> behavior question
Date Tue, 03 Feb 2004 21:30:38 GMT
Mark Menard wrote:
> First I have been struggling with this for a while now. I'm also new to JSP
> having used XMLC for presentation in the past.
> 
> I have the following page:
> 
> 1:  <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
> 2:  <%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
> 3:
> 4:  <c:set var="var1" value="var1" scope="page" />
> 5:  <c:out value="${var1}" />
> 6:  <bean:define id="var2" value="var2" toScope="page" />
> 7:  <%= var2 %>
> 8:
> 9:  <%@ include file="/mark/dumpscopes.jsp" %>
> 
> This runs fine, but if I change the <c:out> on line 5 to <%= var1 %> I get
> the following compilation error:
> 
> Generated servlet error:
>     [javac] Compiling 1 source file
>     [javac] 
> /Users/mark/opt/JBoss-3.2.3/server/default/work/MainEngine/localhost/mori/ma
> rk/mypage_jsp.java:65: cannot resolve symbol
>     [javac] symbol  : variable var1
>     [javac] location: class org.apache.jsp.mypage_jsp
>     [javac]       out.print( var1 );
>     [javac]                  ^
>     [javac] 1 error
> 
> 
> I have looked at the source for <c:set> and <bean:define> and if I'm looking
> at it right they both set the variable in the same manner:
> 
>>>From org.apache.struts.taglib.bean.DefineTag line 288
> (jakarta-struts-1.1-src/src/share/org/apache/struts/taglib/bean/DefineTag.ja
> va):
> 
>         pageContext.setAttribute(id, value, inScope);
> 
>>>From org.apache.taglibs.standard.tag.common.core.SetSupport line 144
> (jakarta-taglibs-standard-1.0.5-src/standard/src/org/apache/taglibs/standard
> /tag/common/core/SetSupport.java):
> 
>         pageContext.setAttribute(var, result, scope);
> 
> I'm curious as to why <%= %> works with a variable defined using
> <bean:define> but not with one defined using <c:set>.
> 
> Additionally I have dumped the scope to see if var1 exists in the page
> context when using the <c:out> version and it is there.
> 
> Environment:
> 
> Jboss-3.2.3 w/ included Tomcat 4.1.29
> OS X Panther 10.3.2 w/ JDK 1.4.2_03
> Ant 1.6
> 
> Thanks much,

For a tag handler to cause a scripting variable (i.e., a local variable
in the Java method that represents the page logic) to be declared and
assigned, the tag handler must declare that it's doing so, either with
the <variable> element in the TLD or using a TagExtraInfo class. See the
JSP spec for details. The JSTL tags don't, but the Struts tags do.

If you need to expose a variable set by JSTL as a scripting variable,
use <jsp:useBean>, e.g.,

   <c:set var="var1" value="var1" scope="page" />
   <jsp:useBean id="var1" class="java.lang.String" />
   <%= var1 %>

Hans
-- 
Hans Bergsten                                <hans@gefionsoftware.com>
Gefion Software                       <http://www.gefionsoftware.com/>
Author of O'Reilly's "JavaServer Pages", covering JSP 2.0 and JSTL 1.1
Details at                                    <http://TheJSPBook.com/>


---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org


Mime
View raw message