You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by otisg <ot...@ureach.com> on 2003/12/09 20:13:25 UTC

Q: c:forEach, c:import and variable scope?

Hello,

Here is the problem (using [] to avoid problems with email
clients not handling HTML well).

Summary:
c:forEach loop, inside it c:import, but the c:import-ed JSP does
not see the var from the c:forEach loop.

[c:forEach var="foo" items="${bars}"]
  [c:import url="some/page.jsp"/]
[/c:forEach]

In this page.jsp I try to access ${foo}, like so:
[c:out value="${foo}"/]

No go.  ${foo} seems undefined there :(  page.jsp does not see
it.  Scope issue?

I then tried adding the following inside that c:forEach:
[c:set var="newFoo" value="${foo}" scope="request"/]

However, that c:import-ed page.jsp does not see ${newFoo}
either. :(

I am using jakarta-taglibs 1.0.3 with JBoss/Jetty.

Is the above supposed to work?
How do I get the import-ed page.jsp to see a variable defined in
the page that imported it?

Thanks,
Otis


________________________________________________
Get your own "800" number
Voicemail, fax, email, and a lot more
http://www.ureach.com/reg/tag

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


Re: Q: c:forEach, c:import and variable scope?

Posted by Martin Cooper <ma...@apache.org>.
On Tue, 9 Dec 2003, otisg wrote:

> Hello,
>
> Here is the problem (using [] to avoid problems with email
> clients not handling HTML well).
>
> Summary:
> c:forEach loop, inside it c:import, but the c:import-ed JSP does
> not see the var from the c:forEach loop.
>
> [c:forEach var="foo" items="${bars}"]
>   [c:import url="some/page.jsp"/]
> [/c:forEach]
>
> In this page.jsp I try to access ${foo}, like so:
> [c:out value="${foo}"/]
>
> No go.  ${foo} seems undefined there :(  page.jsp does not see
> it.  Scope issue?

Yup. As Hans said, you need to promote 'foo' to request scope.

>
> I then tried adding the following inside that c:forEach:
> [c:set var="newFoo" value="${foo}" scope="request"/]
>
> However, that c:import-ed page.jsp does not see ${newFoo}
> either. :(

Hmm. This works fine for me...

--
Martin Cooper


>
> I am using jakarta-taglibs 1.0.3 with JBoss/Jetty.
>
> Is the above supposed to work?
> How do I get the import-ed page.jsp to see a variable defined in
> the page that imported it?
>
> Thanks,
> Otis
>
>
> ________________________________________________
> Get your own "800" number
> Voicemail, fax, email, and a lot more
> http://www.ureach.com/reg/tag
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
>
>

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