You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Micael <ca...@harbornet.com> on 2003/04/13 08:37:53 UTC
Re: Examples for Newbies and Question for
Oldbies
Forgot to ask my question: Why are there two skips on the vector results?
At 11:29 PM 4/12/03 -0700, you wrote:
>I get the following readout for a vector iteration with the code which
>immediately follows:
>
>READOUT IS:
>
>Vector [com.michaelmcgrady.dao.User@1a6b028,
>com.michaelmcgrady.dao.User@772046, com.michaelmcgrady.dao.User@e80317,
>com.michaelmcgrady.dao.User@22e3ac, com.michaelmcgrady.dao.User@916ab8,
>com.michaelmcgrady.dao.User@f55759]
>
>Next element1 is Aa
>Next element2 is
>Next element1 is
>Next element2 is Aaa
>Next element1 is Ab
>Next element2 is
>Next element1 is
>Next element2 is Abb
>Next element1 is Ac
>Next element2 is
>Next element1 is
>Next element2 is Acc
>
>
>Hashtable {c=cc, b=bb, a=aa}
>
>Next element3 is c
>Next element4 is cc
>Next element3 is b
>Next element4 is bb
>Next element3 is a
>Next element4 is aa
>
>
>Map {root=com.michaelmcgrady.dao.User@139a0dc,
>visitor=com.michaelmcgrady.dao.User@6fd560}
>
>Next element5 is root
>Next element5 is com.michaelmcgrady.dao.User@139a0dc
>Next element5 is visitor
>Next element5 is com.michaelmcgrady.dao.User@6fd560
>
>
>
>CODE IS:
>
>
>
><%@ page language='java' %>
><%@ page import='java.util.Hashtable' %>
><%@ page import='java.util.Map' %>
><%@ page import='java.util.Vector' %>
><%@ page import='com.michaelmcgrady.dao.User' %>
><%@ page import='com.michaelmcgrady.dao.UserDAO' %>
><%@ taglib uri='struts-logic' prefix='logic' %>
><%@ taglib uri='struts-bean' prefix='bean' %>
><%@ taglib uri='struts-html' prefix='html' %>
>
><%
> Vector vector = new Vector(89);
> vector.add(new User().setName("Aa"));
> vector.add(new User().setPassword("Aaa"));
> vector.add(new User().setName("Ab"));
> vector.add(new User().setPassword("Abb"));
> vector.add(new User().setName("Ac"));
> vector.add(new User().setPassword("Acc"));
> request.setAttribute("aname", vector);
>
> Hashtable hashtable = new Hashtable(89);
> hashtable.put("a", "aa");
> hashtable.put("b", "bb");
> hashtable.put("c", "cc");
> request.setAttribute("yourchoice", hashtable);
>
>
> Map map = UserDAO.getUsers();
> request.setAttribute("mymap", map);
>%>
>
>Vector <%= vector %>
>
>Next element1 is
>Next element2 is
>
>
>Hashtable <%= hashtable %>
>
>Next element3 is
>Next element4 is
>
>
>Map <%= map %>
>
>Next element5 is
>Next element5 is
>LEGAL NOTICE This electronic mail transmission and any accompanying
>documents contain information belonging to the sender which may be
>confidential and legally privileged. This information is intended only for
>the use of the individual or entity to whom this electronic mail
>transmission was sent as indicated above. If you are not the intended
>recipient, any disclosure, copying, distribution, or action taken in
>reliance on the contents of the information contained in this transmission
>is strictly prohibited. If you have received this transmission in error,
>please delete the message. Thank you
>--------------------------------------------------------------------- To
>unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org For
>additional commands, e-mail: struts-user-help@jakarta.apache.org
LEGAL NOTICE
This electronic mail transmission and any accompanying documents contain
information belonging to the sender which may be confidential and legally
privileged. This information is intended only for the use of the
individual or entity to whom this electronic mail transmission was sent as
indicated above. If you are not the intended recipient, any disclosure,
copying, distribution, or action taken in reliance on the contents of the
information contained in this transmission is strictly prohibited. If you
have received this transmission in error, please delete the message. Thank
you
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
CODE -- Sigh!
Posted by Micael <ca...@harbornet.com>.
Sorry about the prior mess -- the road to hell, and all that.
ADD OBJECTS TO SCOPE:
request.setAttribute("yourchoice", hashtable);
request.setAttribute("aname", vector);
request.setAttribute("mymap", map);
WRITE VALUES TO JSP PAGE
Vector <%= vector %><br><br>
<logic:iterate id="options" name="aname">
NAME: <bean:write name="options" property="name"/><br>
PASSWORD: <bean:write name="options" property="password"/><br>
</logic:iterate>
<br><br>Hashtable <%= hashtable %><br><br>
<logic:iterate id="anything" name="yourchoice">
Next element3 is <bean:write name="anything" property="key"/><br>
Next element4 is <bean:write name="anything" property="value"/><br>
</logic:iterate>
<br><br>Map <%= map %><br><br>
<logic:iterate id="something" name="mymap">
Next element5 is <bean:write name="something" property="key"/><br>
Next element5 is <bean:write name="something" property="value"/><br>
</logic:iterate>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
THE REST OF THE CODERe:
Examples for Newbies and Question for Oldbies
Posted by Micael <ca...@harbornet.com>.
<%
Vector vector = new Vector(89);
User user1 = new User();
user1.setName("Aa");
user1.setPassword("Aaa");
vector.add(user1);
User user2 = new User();
user2.setName("Aa");
user2.setPassword("Aaa");
vector.add(user2);
User user3 = new User();
user3.setName("Aa");
user3.setPassword("Aaa");
vector.add(user3);
request.setAttribute("aname", vector);
Hashtable hashtable = new Hashtable(89);
hashtable.put("a", "aa");
hashtable.put("b", "bb");
hashtable.put("c", "cc");
request.setAttribute("yourchoice", hashtable);
Map map = UserDAO.getUsers();
request.setAttribute("mymap", map);
%>
<html:html locale='true'>
<body>
Vector <%= vector %><br><br>
<logic:iterate id="options" name="aname">
NAME: <bean:write name="options" property="name"/><br>
PASSWORD: <bean:write name="options" property="password"/><br>
</logic:iterate>
<br><br>Hashtable <%= hashtable %><br><br>
<logic:iterate id="anything" name="yourchoice">
Next element3 is <bean:write name="anything" property="key"/><br>
Next element4 is <bean:write name="anything" property="value"/><br>
</logic:iterate>
<br><br>Map <%= map %><br><br>
<logic:iterate id="something" name="mymap">
Next element5 is <bean:write name="something" property="key"/><br>
Next element5 is <bean:write name="something" property="value"/><br>
</logic:iterate>
</body>
</html:html>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
CODE EXAMPLE: Iterate correct examples for
newbies: Re: Examples for Newbies and Question for
Oldbies
Posted by Micael <ca...@harbornet.com>.
Okay, I got the answer. What a foobar -- I mean foopah. Here is an
example of how it works for <logic:iterator> for newbies. I wish I would
have had this when I started.
<%@ page language='java' %>
<%@ page import='java.util.Hashtable' %>
<%@ page import='java.util.Map' %>
<%@ page import='java.util.Vector' %>
<%@ page import='com.michaelmcgrady.dao.User' %>
<%@ page import='com.michaelmcgrady.dao.UserDAO' %>
<%@ taglib uri='struts-logic' prefix='logic' %>
<%@ taglib uri='struts-bean' prefix='bean' %>
<%@ taglib uri='struts-html' prefix='html' %>
<%
Vector vector = new Vector(89);
User user1 = new User();
user1.setName("Aa");
user1.setPassword("Aaa");
vector.add(user1);
User user2 = new User();
user2.setName("Aa");
user2.setPassword("Aaa");
vector.add(user2);
User user3 = new User();
user3.setName("Aa");
user3.setPassword("Aaa");
vector.add(user3);
request.setAttribute("aname", vector);
Hashtable hashtable = new Hashtable(89);
hashtable.put("a", "aa");
hashtable.put("b", "bb");
hashtable.put("c", "cc");
request.setAttribute("yourchoice", hashtable);
Map map = UserDAO.getUsers();
request.setAttribute("mymap", map);
%>
<html:html locale='true'>
<body>
Vector <%= vector %><br><br>
<logic:iterate id="options" name="aname">
NAME: <bean:write name="options" property="name"/><br>
PASSWORD: <bean:write name="options" property="password"/><br>
</logic:iterate>
<br><br>Hashtable <%= hashtable %><br><br>
<logic:iterate id="anything" name="yourchoice">
Next element3 is <bean:write name="anything" property="key"/><br>
Next element4 is <bean:write name="anything" property="value"/><br>
</logic:iterate>
<br><br>Map <%= map %><br><br>
<logic:iterate id="something" name="mymap">
Next element5 is <bean:write name="something" property="key"/><br>
Next element5 is <bean:write name="something" property="value"/><br>
</logic:iterate>
</body>
</html:html>
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org