> > hi,
> > i am confused about iterating through a map in struts.
[quoted text clipped - 36 lines]
>
> - Show quoted text -
hi,
Thank you for your suggestions.but i have some questions.
<bean:define name="myRequestScopedBean" property="theMap" id="myMap"/>
here we are defining the bean in request scope and the map name,which
is there inside it..am i right?
<logic:iterate id="mapEntry" name="myMap" >
here what is this "myMap"? is it just the id of the
myRequestScopedbean?
> <bean:write name="mapEntry" property="key"/> <bean:write
here mapEntry points to the id of the iterate tag....but what is the
property key?, and also what is the value of the next line.
my doubt is that,do we have to write the getter methods for
"theMap","key","value"...
can you please give me the methods of the form bean....
thanks,
vysh.
Tim B - 10 Apr 2007 05:19 GMT
> > > hi,
> > > i am confused about iterating through a map in struts.
[quoted text clipped - 42 lines]
> here we are defining the bean in request scope and the map name,which
> is there inside it..am i right?
Actually we are finding the bean in request scope. If it's not there,an
exception will be thrown. The bean (form bean or whatever) has a property
named "theMap" which is a java.util.Map
with id="myMap" we are just giving this map a local (to the jsp) name so
we can refer to it later in the logic:iterate tag
> <logic:iterate id="mapEntry" name="myMap" >
> here what is this "myMap"? is it just the id of the
> myRequestScopedbean?
not the id of myRequestScopedBean, but the id of the Map contained in
myRequestScopedBean.
> > <bean:write name="mapEntry" property="key"/> <bean:write
> here mapEntry points to the id of the iterate tag....but what is the
[quoted text clipped - 4 lines]
> thanks,
> vysh.
if theMap is a java.util.Map, the Struts tag will take care of accessing
the keys and values of the Map for you. You must literally use
property="key" and property="value". You do not have to write any getters
and setters other than those in the form bean for "theMap". These will be
in standard bean format - getTheMap and setTheMap.
vyshu - 10 Apr 2007 05:35 GMT
> > > "vyshu" <vysh...@gmail.com> wrote in message
>
[quoted text clipped - 77 lines]
>
> - Show quoted text -
thanks.
but for the methods getTheMap and setTheMap what shoul be the
parameter and the return values.
public Map getTheMap()
{
return this.theMap;
}
public void setTheMap(Map newMap)
{
this.theMap=newMap;
}
is it so?.
thanks,
vysh
vyshu - 10 Apr 2007 06:04 GMT
Cheers!!!!!!!!!!!
i got it!!!!
Thank you so much for helping me.
vysh.
> > hi,
> > i am confused about iterating through a map in struts.
[quoted text clipped - 34 lines]
> name="mapEntry" property="value"/>
> </logic:iterate>
Vyshu,
Just elaborating above example for better understanding.
<bean:define name="myRequestScopedBean" property="theMap" id="myMap"/>
1. myRequestScopedBean- is the bean class(DTO/VO's) in which you will
be decalaring your HashMap as property.
2. theMap- is the name of HashMap, like private HashMap theMap in the
bean class, which you will be populating in Action/impl classes.
3. myMap- is just a reference variable with which this HashMap will be
refered within this scope.
<logic:iterate id="mapEntry" name="myMap" >
Now as you have hashmap reference so you iterate over it, giving it a
id for next scope in which you loop/iterated within the entry and get
its keys and values printed out.
-Chandan
vyshu - 10 Apr 2007 05:28 GMT
> > "vyshu" <vysh...@gmail.com> wrote in message
>
[quoted text clipped - 59 lines]
>
> - Show quoted text -
hi,
thanks,
ok,i will try to explain what i understood.
In my form bean itself i will declare the HashMap.
//*****************************************************
public class LoginForm extends ActionForm
{
private HashMap themap;
}
//**********************************
Now let me assign the entire form to a request scope in my Action
class.
ActionForm form;
LoginForm object=(LoginForm)form;
request.setAttribute("myRequestScopedBean",form);
//**********************************************
Now can you explain what and all getter methods i need for acessing
the values of the map, and also where to write it.
and I want to display the values of the map as the options of a select
tag!..
waiting for your reply.
thanks,
vysh.
> > hi,
> > i am confused about iterating through a map in struts.
[quoted text clipped - 36 lines]
>
> - Show quoted text -
hi,
now when i am trying with the same code what you have given,its
throwing an exception "Cannot find bean: "mapEntry" in any scope".why
it is so?
thanks,
vysh.