Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

logic:iterate tag

 
sha ram
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can some one help me in using logic tag in struts.
I have a simple form and one of the fields returns Hashmap
In my action form class I have getHashmap()..returns hashmap
I have a result jsp page which should retrieve the values from hashmap.
How to do this using logic tag?
[ December 11, 2003: Message edited by: sha ram ]
 
sha ram
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<html:html>
<HEAD>
<%@ page import="java.util.*" %>
<%@ page import="test.struts_example.*" %>
<TITLE></TITLE>
</HEAD>
<jsp:useBean id="submitForm" class="test.struts_example.SubmitForm"
scope="request"></jsp:useBean>
<BODY>
P>Thank you
<%=request.getAttribute("name")%>
</P>
************************************************
<%
java.util.HashMap tps = submitForm.getToppings();
Set keys = tps.keySet();
Iterator I = keys.iterator();
while(I.hasNext())
{
String myKey = (String)I.next();
String myValue = (String)submitForm.getTopping(myKey);
out.println(myKey +" "+ myValue);
}
%>
*****************************
I want to use iterator tag instaed of the code marked between ****
Please help asap.
</BODY>
</html:html>
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64973
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to the Struts forum.
bear
 
sha ram
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<%
Map map = new HashMap();
map.put("seven", new Integer(7));
map.put("nine", new Integer(9));
map.put("thirteen", new Integer(13));
request.setAttribute("map",map);
%>
<logic:iterate id="hs" name="map">
<bean:write name="hs" property="key"/>=
<bean:write name="hs" property="value"/>
</logic:iterate>
I found this sample code in net. But I get error. How to resolve?
[Servlet Error]-[Cannot find bean hs in any scope]: javax.servlet.jsp.JspException: Cannot find bean hs in any scope
 
David Yutzy
tumbleweed and gunslinger
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I used the following code and it worked for me.
 
sha ram
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. I tried removing all other parts of the code and just added what you sent. It works fine for me too.
Can you help me with the code below. I need to put the below code using iterate tag.
<%
/*
java.util.HashMap tps = submitForm.getToppings();
Set keys = tps.keySet();
Iterator I = keys.iterator();
while(I.hasNext())
{
String myKey = (String)I.next();
String myValue = (String)submitForm.getTopping(myKey);
out.println(myKey +" "+ myValue);
}*/
%>
 
Uwe Barthel
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
that's what the code snip of sha ram do.
Sorry for my bad english.
-get the hashtable and iterate about ( <logic:iterate ...> )
- write down key and value ( <bean:write name="hs" property="key" ... /> )
what do you want really ?
thx
Uwe Barthel
[ December 22, 2003: Message edited by: Uwe Barthel ]
[ December 22, 2003: Message edited by: Uwe Barthel ]
 
Sandeep Ghosh
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,
I want to iterate over hashmap whose value is not a String but a object using logic:iterate tag.
Say


Please help me out

Thanks in adv
[ April 28, 2005: Message edited by: Nataraj Ramesh ]
 
Anand Ko
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think in the iterator i.e for each loop you need to define a bean tag
with the value of the HashMap.
Say
<bean efine id="beanname" name="hs" property="value" type="ClassNameofObject"/>
Then try to get the values from this bean you created.
<bean:write name="beanname" property="id"/>
<bean:write name="beanname" property="value"/>
Hope this should help.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic