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 Neil Aggarwal <ne...@JAMMConsulting.com> on 2006/12/11 23:35:02 UTC

Var for c:forEach loop is always null

Hello:

According to the c:forEach doc, the var attribute of the
c:forEach tag has nested visibility.

What does that mean?  

I am trying to access the current object of the iteration
and always getting null.

Here is an example:

<%@page language="java" %>
<%@page import="java.util.*" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<%
	HashSet<String> mySet = new HashSet<String>();
	mySet.add("Str1");
	mySet.add("Str2");
	mySet.add("Str3");
	mySet.add("Str4");
	mySet.add("Str5");
	mySet.add("Str6");
	mySet.add("Str7");
	
	request.setAttribute("mySet",mySet);
%>	

<c:forEach var="str" items="${mySet}">
  <% String str = (String)request.getAttribute("str"); %>
	<p>
	<%= str %>
</c:forEach>

The value of str is always null.

How can I fix this?

Thanks,
	Neil

--
Neil Aggarwal, (214)986-3533, www.JAMMConsulting.com
FREE! Eliminate junk email and reclaim your inbox.
Visit http://www.spammilter.com for details.


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


Re: Netbeans Release 3.6

Posted by Kris Schneider <kr...@dotech.com>.
T. Lamine Ba wrote:
> Hi all,
> 
> I need to re-install an old webapp running on netbeans 3.6
> The release (netbeans 3.6) is not available on netbeans website anymore.
> Can anyone point me to a site that has it?

http://www.netbeans.info/downloads/dev.php

> Thanks,
> Lamine.

-- 
Kris Schneider <ma...@dotech.com>
D.O.Tech       <http://www.dotech.com/>

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


Netbeans Release 3.6

Posted by "T. Lamine Ba" <la...@hotmail.com>.
Hi all,

I need to re-install an old webapp running on netbeans 3.6
The release (netbeans 3.6) is not available on netbeans website anymore.
Can anyone point me to a site that has it?

Thanks,
Lamine.


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


Re: Var for c:forEach loop is always null

Posted by Martin Cooper <ma...@apache.org>.
On 12/11/06, Neil Aggarwal <ne...@jammconsulting.com> wrote:
>
> Hello:
>
> According to the c:forEach doc, the var attribute of the
> c:forEach tag has nested visibility.
>
> What does that mean?


>From the spec:

"Nested scoped variables are only visible within the body of the action and
are stored in "page" scope."

I am trying to access the current object of the iteration
> and always getting null.
>
> Here is an example:
>
> <%@page language="java" %>
> <%@page import="java.util.*" %>
> <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
>
> <%
>         HashSet<String> mySet = new HashSet<String>();
>         mySet.add("Str1");
>         mySet.add("Str2");
>         mySet.add("Str3");
>         mySet.add("Str4");
>         mySet.add("Str5");
>         mySet.add("Str6");
>         mySet.add("Str7");
>
>         request.setAttribute("mySet",mySet);
> %>
>
> <c:forEach var="str" items="${mySet}">
>   <% String str = (String)request.getAttribute("str"); %>
>         <p>
>         <%= str %>
> </c:forEach>
>
> The value of str is always null.
>
> How can I fix this?


Well, for starters, var is page scoped and not request scoped. But why are
you using JSTL for your loop and then using scripting expressions to access
the iterator values? If you use <c:out value="${str}"/> or even just ${str}
you won't see this kind of problem.

--
Martin Cooper


Thanks,
>         Neil
>
> --
> Neil Aggarwal, (214)986-3533, www.JAMMConsulting.com
> FREE! Eliminate junk email and reclaim your inbox.
> Visit http://www.spammilter.com for details.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
>
>

RE: Var for c:forEach loop is always null

Posted by Steve Duran <st...@nmmcc.com>.
  Try this:

<%
	HashSet<String> mySet = new HashSet<String>();
	mySet.add("Str1");
	mySet.add("Str2");
	mySet.add("Str3");
	mySet.add("Str4");
	mySet.add("Str5");
	mySet.add("Str6");
	mySet.add("Str7");
	
      // putting the variable in the request scope
	request.setAttribute("mySet",mySet);
   
      // could put it in the page scope like this
      pageContext.setAttribute( "list", vList );
%>	

<%-- normally str would be set in the page scope, so specify the request
scope --%>
<c:forEach var="str" items="${requestScope.mySet}" scope="request">

  <%-- here, you're looking for the variable "str" in the request scope
--%>
  <% String str = (String)request.getAttribute("str"); %>
	<p>
	<%= str %>
</c:forEach>

-----Original Message-----
From: Neil Aggarwal [mailto:neil@JAMMConsulting.com] 
Sent: Monday, December 11, 2006 3:35 PM
To: taglibs-user@jakarta.apache.org
Subject: Var for c:forEach loop is always null


Hello:

According to the c:forEach doc, the var attribute of the c:forEach tag
has nested visibility.

What does that mean?  

I am trying to access the current object of the iteration
and always getting null.

Here is an example:

<%@page language="java" %>
<%@page import="java.util.*" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<%
	HashSet<String> mySet = new HashSet<String>();
	mySet.add("Str1");
	mySet.add("Str2");
	mySet.add("Str3");
	mySet.add("Str4");
	mySet.add("Str5");
	mySet.add("Str6");
	mySet.add("Str7");
	
	request.setAttribute("mySet",mySet);
%>	

<c:forEach var="str" items="${mySet}">
  <% String str = (String)request.getAttribute("str"); %>
	<p>
	<%= str %>
</c:forEach>

The value of str is always null.

How can I fix this?

Thanks,
	Neil

--
Neil Aggarwal, (214)986-3533, www.JAMMConsulting.com
FREE! Eliminate junk email and reclaim your inbox.
Visit http://www.spammilter.com for details.


---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
**************************************************************************************************
CONFIDENTALITY NOTICE: This e-mail communication and any attachments may contain confidential and 
privileged information protected from disclosure by law. It is intended only for the use of the specified 
recipients.  Any unauthorized review, use, disclosure, distribution or any action based on this material is 
prohibited.  If you are not the intended recipient, please contact the sender by reply e-mail and destroy all 
copies of the original message.
**************************************************************************************************


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