You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-dev@jakarta.apache.org by Garrett Smith <ja...@yahoo.com> on 2002/10/23 14:04:12 UTC

Re: [taglibs] how to iterate over an Enumeration (with tags)? (getting closer)

I found a relevant page with an example:
http://jakarta.apache.org/taglibs/doc/standard-doc/standard/GettingStarted.html
from there, I found:
http://java.sun.com/webservices/docs/1.0/tutorial/doc/JSTL5.html#63882

The page below compares using c:forEach with using a scriptlet. The scriptlet
gives the desired result but the c:forEach loop yeilds an error. What is the
correct syntax, please? Where can I obtain an online reference?

		<h1>Active Users</h1>
		
		<h2>With c:forEach</h2>		
  <c:forEach var='user' items='${applicationScope.users}'>
   <c:out value="${user.username}"/>
  </c:forEach>
				

		<h2>With Scriptlet</h2>		
<%
  Hashtable users = (Hashtable)application.getAttribute("users");
  if(users != null && users.size() > 0){
	
  for(Enumeration e = users.elements() ; e.hasMoreElements() ;){
    User user = (User)e.nextElement();
%>

  <ul>
    <li><%= user.getUsername() %></li>
  </ul>
<%
  }
}
%>

The c:tag produces an error:
ServletException: An error occurred while evaluating custom action attribute
"value" with value "${user.entry}": Unable to find a value for "entry" in
object of class "java.util.Hashtable$Entry" using operator "." (null)


--- Garrett Smith <ja...@yahoo.com> wrote:
> How can I iterate over a collection? 
> 
> The collection is going to be application-scoped. I don't like scriptlets,
> and
> I know that this is possible w/jstl. Or maybe there is a smaller library
> (considering my available space on my hard drive and on my host).
> 
> I am just guessing because I couldn't find the documentation. The collection
> is
> a Hashtable, so I'll be iterating over an enumeration of an unknown length. 
> 
> 
> <%@ taglib uri='/WEB-INF/tlds/c.tld' prefix='c'%>
> 
> <c:For iterations='10' varName="users" begin='1'>
>    <%= users[i] %> 
>   </c:if>
> 
> that doesn't work, but the example below does:
> 
> 		<h1>Active Users</h1>
> <%
>   Hashtable users = (Hashtable)application.getAttribute("users");
>   if(users != null && users.size() > 0){
> 	
>   for(Enumeration e = users.elements() ; e.hasMoreElements() ;){
>     User user = (User)e.nextElement();
> %>
> 
>   <ul>
>     <li><%= user.getUsername() %></li>
>   </ul>
> <%
>   }
> }
> %>
> 
> 
> 
> =====
> Garrett Needs A Job
> 
> __________________________________________________
> Do you Yahoo!?
> Y! Web Hosting - Let the expert host your web site
> http://webhosting.yahoo.com/
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 


=====
Garrett Needs A Job

__________________________________________________
Do you Yahoo!?
Y! Web Hosting - Let the expert host your web site
http://webhosting.yahoo.com/

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [taglibs] how to iterate over an Enumeration (with tags)? (getting closer)

Posted by Shawn Bayern <ba...@essentially.net>.
On Wed, 23 Oct 2002, Garrett Smith wrote:

> The page below compares using c:forEach with using a scriptlet. The
> scriptlet gives the desired result but the c:forEach loop yeilds an
> error. What is the correct syntax, please? Where can I obtain an
> online reference?

The JSTL specification is available from

  http://java.sun.com/products/jstl

The <c:forEach> tag iterates over objects that implement Enumeration.  
Note that Enumeration is an out-of-date class, but it'll work fine with
<c:forEach>.

> The c:tag produces an error:
> ServletException: An error occurred while evaluating custom action attribute
> "value" with value "${user.entry}": Unable to find a value for "entry" in
> object of class "java.util.Hashtable$Entry" using operator "." (null)

I don't believe this error matches the code that you posted.  Could you
confirm that this error comes from the same version of the same JSP page
you posted?

-- 
Shawn Bayern
"JSTL in Action"   http://www.jstlbook.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>