You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by andy wix <st...@hotmail.com> on 2004/09/01 15:45:30 UTC

Basic JSTL
Hi,

In trying to resolve another (more Struts related!) problem someone 
suggested using a <c:forEach tag, but I can't get it to output anything to 
the screen.  I have omitted the html for clarity but have created a simple 
class called test that has 1 instance variable called name and a getter and 
setter.

<%@ taglib uri="jstl/c" prefix="c" %>

<%
  Test con1 = new Test();
  Test con2 = new Test();
  con1.setName("Fred");
  con2.setName("Dog");

  ArrayList xxx = new ArrayList();
  xxx.add(con1);
  xxx.add(con2);
%>

<c:forEach items="${xxx}" var="temp">
   Name: <c:out value="${temp.name}" />
</c:forEach>

Should this ouput the 2 names to the page?
I can do a <c:out successfully on its own so I suspect the taglib is seen 
correctly.

Thanks,
Andy

_________________________________________________________________
Express yourself with cool new emoticons http://www.msn.co.uk/specials/myemo


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


Re: Basic JSTL Posted by Brett Connor <br...@spamcop.net>.
xxx needs to be somewhere accessible to the c:forEach tag. Do a search 
on scoped variables. This can be done in your scriptlet or in the action 
that forwards to this jsp.
Brett

andy wix wrote:

> Hi,
>
> In trying to resolve another (more Struts related!) problem someone 
> suggested using a <c:forEach tag, but I can't get it to output 
> anything to the screen.  I have omitted the html for clarity but have 
> created a simple class called test that has 1 instance variable called 
> name and a getter and setter.
>
> <%@ taglib uri="jstl/c" prefix="c" %>
>
> <%
>  Test con1 = new Test();
>  Test con2 = new Test();
>  con1.setName("Fred");
>  con2.setName("Dog");
>
>  ArrayList xxx = new ArrayList();
>  xxx.add(con1);
>  xxx.add(con2);
> %>
>
> <c:forEach items="${xxx}" var="temp">
>   Name: <c:out value="${temp.name}" />
> </c:forEach>
>
> Should this ouput the 2 names to the page?
> I can do a <c:out successfully on its own so I suspect the taglib is 
> seen correctly.
>
> Thanks,
> Andy
>
> _________________________________________________________________
> Express yourself with cool new emoticons 
> http://www.msn.co.uk/specials/myemo
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

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


Re: Basic JSTL Posted by Bill Siggelkow <bi...@bellsouth.net>.
Okay, Andy -- JSTL operates on scoped variables not scripting variables. 
You are trying to access scripting variables. I found this good primer 
on JSTL that explains this at 
http://www-106.ibm.com/developerworks/java/library/j-jstl0211.html

andy wix wrote:
> Hi,
> 
> In trying to resolve another (more Struts related!) problem someone 
> suggested using a <c:forEach tag, but I can't get it to output anything 
> to the screen.  I have omitted the html for clarity but have created a 
> simple class called test that has 1 instance variable called name and a 
> getter and setter.
> 
> <%@ taglib uri="jstl/c" prefix="c" %>
> 
> <%
>  Test con1 = new Test();
>  Test con2 = new Test();
>  con1.setName("Fred");
>  con2.setName("Dog");
> 
>  ArrayList xxx = new ArrayList();
>  xxx.add(con1);
>  xxx.add(con2);
> %>
> 
> <c:forEach items="${xxx}" var="temp">
>   Name: <c:out value="${temp.name}" />
> </c:forEach>
> 
> Should this ouput the 2 names to the page?
> I can do a <c:out successfully on its own so I suspect the taglib is 
> seen correctly.
> 
> Thanks,
> Andy
> 
> _________________________________________________________________
> Express yourself with cool new emoticons 
> http://www.msn.co.uk/specials/myemo


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