| Author |
logic:iterate tag
|
sha ram
Greenhorn
Joined: Nov 25, 2003
Posts: 12
|
|
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
Joined: Nov 25, 2003
Posts: 12
|
|
<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
Joined: Jan 10, 2002
Posts: 56191
|
|
Moving to the Struts forum. bear
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
sha ram
Greenhorn
Joined: Nov 25, 2003
Posts: 12
|
|
<% 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
Joined: Jun 29, 2001
Posts: 192
|
|
I used the following code and it worked for me.
|
 |
sha ram
Greenhorn
Joined: Nov 25, 2003
Posts: 12
|
|
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
Joined: Dec 16, 2003
Posts: 9
|
|
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 ]
|
--<br />Sorry for my bad englich
|
 |
Sandeep Ghosh
Ranch Hand
Joined: Jan 23, 2002
Posts: 145
|
|
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
Joined: Dec 03, 2003
Posts: 79
|
|
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.
|
Anand<br />SCJP 1.4, SCWCD 1.4, SCEA 5.0(1/3)
|
 |
 |
|
|
subject: logic:iterate tag
|
|
|