• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

logic:iterate tag

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to the Struts forum.
bear
 
sha ram
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
tumbleweed and gunslinger
Posts: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
}*/
%>
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic