Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Jsp and database using the logic:iterate tag  RSS feed

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys.
I am a new programmer still learning java.Is it possible to use the logic:iterate tag twice in the same JSP.I have used it to retrieve data from the database as follows.

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<html:form action="/User.do?action=add">
<h2>List of users</h2>
<table width="40%" border="3" >
<tr>
<th>UserId</th>
<th>Username</th>
<th>Password</th>
<th>Action</th>
<th>Action</th>
</tr>
<logic:iterate id="elem" name="results" type="za.co.johnboy.vo.UserVO">
<tr>
<td align="right"><bean:write name="elem" property="userId"/></td>
<td><bean:write name="elem" property="username"/></td>
<td align="right"><bean:write name="elem" property="password"/><br></td>
<td><a href="User.do?action=update&userId=<bean:write name='elem' property='userId'/>">[Update]</a></td>
<td><a href="User.do?action=delete&userId=<bean:write name='elem' property='userId'/>">[Delete]</a></td>
</tr>
</logic:iterate>
<tr>
<td colspan="6" align="center">
<html:submit value="Add User"/>
</td>
</tr>
</table>
</html:form>
Now I need to iterate through a different class in order to get the output on the same page. Please help.
 
Author and ninkuma
Marshal
Posts: 66799
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What exactly is "results"?

Some constructs are suitable for multiple iterations, and some are not.
[ November 06, 2006: Message edited by: Bear Bibeault ]
 
MaryT Tsele
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear.

Thank you for attending to my question.And please accept my appology for not using the forum.

The �results� is a collection of data that I am getting out of the database using the ff method from a class called UserDAO. So I have another class which is called RoleDAO which retrieves the roles for the users from the database in the same way as the UserDAO class. I need to put the output of both classes(results and roleResults) on the same jsp page.

[code:]
public class UserDAO {

public Collection getAllUsers(){

Session session = SessionUtil.currentSession();
Criteria criteria = session.createCriteria(User.class);
criteria.addOrder(Order.asc("username"));
Collection result = criteria.list();
return result;
}
}
[code:]

Class for Roles:

[code:]
public class RoleDAO {

public Collection getRoles(){

Session session = SessionUtil.currentSession();
System.out.println("Staring the session");
Criteria criteria = session.createCriteria(Role.class);
criteria.addOrder(Order.asc("roleName"));
Collection roleResult = criteria.list();
return roleResult;
}
}
[code:]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66799
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see that you are trying to use the code tags, but not correctly. Please read this for help on that.

Whatever structure you are passng to the page for iteration implements the Collection interface, but we don't know much else about it.

Constructs such as Lists and Maps are multiply iterable, while Enumerations and Iterators are not.

You could stick a line of code such as



and that would tell you the class type of the collection for further investigation.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!