how to iterate through a map in struts

Discussion in 'Java' started by vyshu, Apr 9, 2007.

  1. vyshu

    vyshu Guest

    hi,
    i am confused about iterating through a map in struts.
    i hav a form bean LoginForm.and a getter mathod getID(),which returns
    the values of a map if passed the key as parameter....my code..
    /*public String getId(String key)
    {
    return (String)mapelements(key);
    }
    public Object mapelements(String key)
    {
    Map x=new HashMap();
    x.put("1","vaisahk");
    x.put("2","jovin");
    x.put("3","praveen");
    x.put("4","subhash");
    return x.get(key);
    }
    */
    now i want to print this in the jsp page where i am fowarding from
    here..
    this is my action code..
    LoginForm obj=(LoginForm)form;
    sess=obj.getUser();
    HttpSession session=req.getSession();
    session.setAttribute("usersession",form);

    and in the forwarded jsp page i want to print the values of the
    map....

    please help....
    vyshu, Apr 9, 2007
    #1
    1. Advertising

  2. vyshu

    ck Guest

    > "vyshu" <> wrote:
    > i hav a form bean LoginForm.and a getter mathod getID(),which returns
    > the values of a map if passed the key as parameter....my code..
    > /*public String getId(String key)
    > {
    > return (String)mapelements(key);
    > }
    > public Object mapelements(String key)
    > {
    > Map x=new HashMap();
    > x.put("1","vaisahk");
    > x.put("2","jovin");
    > x.put("3","praveen");
    > x.put("4","subhash");
    > return x.get(key);
    > }
    > */
    > now i want to print this in the jsp page where i am fowarding from
    > here..
    > this is my action code..
    > LoginForm obj=(LoginForm)form;
    > sess=obj.getUser();
    > HttpSession session=req.getSession();
    > session.setAttribute("usersession",form);
    >
    > and in the forwarded jsp page i want to print the values of the
    > map....


    Why not set the 'id' in the session scope rather than setting the
    entire form?

    > HttpSession session=req.getSession();
    > session.setAttribute("usersession",form);


    Instead of the above try this

    session.setAttribute("userId",form.getId(key));

    In jsp, use JSTL to get the Id like this

    ${userId}

    Would this make it simpler?

    By the way to access mapelements() method you would need to provide a
    getter method.

    --
    Ck
    http://www.gfour.net
    ck, Apr 9, 2007
    #2
    1. Advertising

  3. vyshu

    vyshu Guest

    hi,
    thank you for your reply...but i am very new to struts for
    understanding the exact thing.....
    i will try to explain you what i hav understood so far..
    from the bigining.......
    in the application what i am trying to build...there is be a login
    form which accepts the user id and password....i hav written the
    formbean...its LoginForm which has the setter and getter methods of
    the form properties....
    now i want to extract customer id's from the database and display it
    in the next jsp page....
    for that actually i was trying with the demo values.......
    if in the same LoginForm i assign the getter method for the map will
    it give any errors.....lots of confusions!!!!!!!
    it would be really helpful if u can explain me the entire stuff from
    assigning the values to the map....writing the getter and setter
    methods...and displaying it in the form using..a select option!!....
    ........plz help..
    vyshu, Apr 9, 2007
    #3
  4. vyshu

    vyshu Guest

    On Apr 9, 4:44 pm, "vyshu" <> wrote:
    > hi,
    > thank you for your reply...but i am very new to struts for
    > understanding the exact thing.....
    > i will try to explain you what i hav understood so far..
    > from the bigining.......
    > in the application what i am trying to build...there is be a login
    > form which accepts the user id and password....i hav written the
    > formbean...its LoginForm which has the setter and getter methods of
    > the form properties....
    > now i want to extract customer id's from the database and display it
    > in the next jsp page....
    > for that actually i was trying with the demo values.......
    > if in the same LoginForm i assign the getter method for the map will
    > it give any errors.....lots of confusions!!!!!!!
    > it would be really helpful if u can explain me the entire stuff from
    > assigning the values to the map....writing the getter and setter
    > methods...and displaying it in the form using..a select option!!....
    > .......plz help..


    and on the process i was just trying to just display the values on the
    jsp page...
    i just declared a getId() method in the LoginForm which returns a
    string value if passed the key.....
    assigned the complete bean to a session...and callled in the jsp
    page.......
    for(int i=1;i<3;i++)
    {
    String nam="id("+i+")";%>
    <html:text name="usersession" property="<%=nam%>"/>
    <%}%>
    it displayed can i do something similar in the other case also,where i
    want the data's inside a select........
    ........................??????????
    thanks,
    vysh
    vyshu, Apr 9, 2007
    #4
  5. vyshu

    Lew Guest

    vyshu wrote:
    > On Apr 9, 4:44 pm, "vyshu" <> wrote:
    >> hi,
    >> thank you for your reply...but i am very new to struts for
    >> understanding the exact thing.....
    >> i will try to explain you what i hav understood so far..
    >> from the bigining.......
    >> in the application what i am trying to build...there is be a login
    >> form which accepts the user id and password....i hav written the
    >> formbean...its LoginForm which has the setter and getter methods of
    >> the form properties....
    >> now i want to extract customer id's from the database and display it
    >> in the next jsp page....
    >> for that actually i was trying with the demo values.......
    >> if in the same LoginForm i assign the getter method for the map will
    >> it give any errors.....lots of confusions!!!!!!!
    >> it would be really helpful if u can explain me the entire stuff from
    >> assigning the values to the map....writing the getter and setter
    >> methods...and displaying it in the form using..a select option!!....
    >> .......plz help..

    >
    > and on the process i was just trying to just display the values on the
    > jsp page...
    > i just declared a getId() method in the LoginForm which returns a
    > string value if passed the key.....
    > assigned the complete bean to a session...and callled in the jsp
    > page.......
    > for(int i=1;i<3;i++)
    > {
    > String nam="id("+i+")";%>
    > <html:text name="usersession" property="<%=nam%>"/>
    > <%}%>
    > it displayed can i do something similar in the other case also,where i
    > want the data's inside a select........
    > .......................??????????
    > thanks,
    > vysh


    Just a side note, not to answer your particular question but to help you get
    better answers and help everyone else to better understand your questions.

    When you post in English there are grammar rules (conventions) to make the
    post more readable. A sentence begins with an upper-case letter and ends with
    a single period, not a series of ellipses. More than one question mark or
    exclamation point in a row is redundant. The word "I" is spelled with an
    upper-case letter. The word "you" is spelled with three letters. The word
    "please" does not have a "z" in it and is spelled with six letters. There
    should be two spaces between sentences.

    When you post code it should be indented similarly to the Sun Java coding
    conventions. It also helps to post an SSCCE.

    The way you posted your messages the sentences are all run together; there is
    no white space or change of letter case to aid readability.

    --
    Lew
    Lew, Apr 9, 2007
    #5
  6. vyshu

    Tim B Guest

    "vyshu" <> wrote in message
    news:...
    > hi,
    > i am confused about iterating through a map in struts.
    > i hav a form bean LoginForm.and a getter mathod getID(),which returns
    > the values of a map if passed the key as parameter....my code..
    > /*public String getId(String key)
    > {
    > return (String)mapelements(key);
    > }
    > public Object mapelements(String key)
    > {
    > Map x=new HashMap();
    > x.put("1","vaisahk");
    > x.put("2","jovin");
    > x.put("3","praveen");
    > x.put("4","subhash");
    > return x.get(key);
    > }
    > */
    > now i want to print this in the jsp page where i am fowarding from
    > here..
    > this is my action code..
    > LoginForm obj=(LoginForm)form;
    > sess=obj.getUser();
    > HttpSession session=req.getSession();
    > session.setAttribute("usersession",form);
    >
    > and in the forwarded jsp page i want to print the values of the
    > map....
    >
    > please help....
    >


    Here's an example using Struts tags.

    <bean:define name="myRequestScopedBean" property="theMap" id="myMap"/>
    <logic:iterate id="mapEntry" name="myMap" >
    <bean:write name="mapEntry" property="key"/> <bean:write
    name="mapEntry" property="value"/>
    </logic:iterate>
    Tim B, Apr 9, 2007
    #6
  7. vyshu

    vyshu Guest

    On Apr 10, 1:46 am, "Tim B" <> wrote:
    > "vyshu" <> wrote in message
    >
    > news:...
    >
    >
    >
    >
    >
    > > hi,
    > > i am confused about iterating through a map in struts.
    > > i hav a form bean LoginForm.and a getter mathod getID(),which returns
    > > the values of a map if passed the key as parameter....my code..
    > > /*public String getId(String key)
    > > {
    > > return (String)mapelements(key);
    > > }
    > > public Object mapelements(String key)
    > > {
    > > Map x=new HashMap();
    > > x.put("1","vaisahk");
    > > x.put("2","jovin");
    > > x.put("3","praveen");
    > > x.put("4","subhash");
    > > return x.get(key);
    > > }
    > > */
    > > now i want to print this in the jsp page where i am fowarding from
    > > here..
    > > this is my action code..
    > > LoginForm obj=(LoginForm)form;
    > > sess=obj.getUser();
    > > HttpSession session=req.getSession();
    > > session.setAttribute("usersession",form);

    >
    > > and in the forwarded jsp page i want to print the values of the
    > > map....

    >
    > > please help....

    >
    > Here's an example using Struts tags.
    >
    > <bean:define name="myRequestScopedBean" property="theMap" id="myMap"/>
    > <logic:iterate id="mapEntry" name="myMap" >
    > <bean:write name="mapEntry" property="key"/> <bean:write
    > name="mapEntry" property="value"/>
    > </logic:iterate>- Hide quoted text -
    >
    > - 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.
    vyshu, Apr 10, 2007
    #7
  8. vyshu

    vyshu Guest

    On Apr 9, 5:43 pm, Lew <> wrote:
    > vyshu wrote:
    > > On Apr 9, 4:44 pm, "vyshu" <> wrote:
    > >> hi,
    > >> thank you for your reply...but i am very new to struts for
    > >> understanding the exact thing.....
    > >> i will try to explain you what i hav understood so far..
    > >> from the bigining.......
    > >> in the application what i am trying to build...there is be a login
    > >> form which accepts the user id and password....i hav written the
    > >> formbean...its LoginForm which has the setter and getter methods of
    > >> the form properties....
    > >> now i want to extract customer id's from the database and display it
    > >> in the next jsp page....
    > >> for that actually i was trying with the demo values.......
    > >> if in the same LoginForm i assign the getter method for the map will
    > >> it give any errors.....lots of confusions!!!!!!!
    > >> it would be really helpful if u can explain me the entire stuff from
    > >> assigning the values to the map....writing the getter and setter
    > >> methods...and displaying it in the form using..a select option!!....
    > >> .......plz help..

    >
    > > and on the process i was just trying to just display the values on the
    > > jsp page...
    > > i just declared a getId() method in the LoginForm which returns a
    > > string value if passed the key.....
    > > assigned the complete bean to a session...and callled in the jsp
    > > page.......
    > > for(int i=1;i<3;i++)
    > > {
    > > String nam="id("+i+")";%>
    > > <html:text name="usersession" property="<%=nam%>"/>
    > > <%}%>
    > > it displayed can i do something similar in the other case also,where i
    > > want the data's inside a select........
    > > .......................??????????
    > > thanks,
    > > vysh

    >
    > Just a side note, not to answer your particular question but to help you get
    > better answers and help everyone else to better understand your questions.
    >
    > When you post in English there are grammar rules (conventions) to make the
    > post more readable. A sentence begins with an upper-case letter and ends with
    > a single period, not a series of ellipses. More than one question mark or
    > exclamation point in a row is redundant. The word "I" is spelled with an
    > upper-case letter. The word "you" is spelled with three letters. The word
    > "please" does not have a "z" in it and is spelled with six letters. There
    > should be two spaces between sentences.
    >
    > When you post code it should be indented similarly to the Sun Java coding
    > conventions. It also helps to post an SSCCE.
    >
    > The way you posted your messages the sentences are all run together; there is
    > no white space or change of letter case to aid readability.
    >
    > --
    > Lew- Hide quoted text -
    >
    > - Show quoted text -


    hi lew,
    I am really sorry.
    I will definitly try to make my questions more readable in future.
    Thankyou for your suggestions.
    thanks,
    vysh
    vyshu, Apr 10, 2007
    #8
  9. vyshu

    chandan Guest

    On Apr 10, 1:46 am, "Tim B" <> wrote:
    > "vyshu" <> wrote in message
    >
    > news:...
    >
    >
    >
    > > hi,
    > > i am confused about iterating through a map in struts.
    > > i hav a form bean LoginForm.and a getter mathod getID(),which returns
    > > the values of a map if passed the key as parameter....my code..
    > > /*public String getId(String key)
    > > {
    > > return (String)mapelements(key);
    > > }
    > > public Object mapelements(String key)
    > > {
    > > Map x=new HashMap();
    > > x.put("1","vaisahk");
    > > x.put("2","jovin");
    > > x.put("3","praveen");
    > > x.put("4","subhash");
    > > return x.get(key);
    > > }
    > > */
    > > now i want to print this in the jsp page where i am fowarding from
    > > here..
    > > this is my action code..
    > > LoginForm obj=(LoginForm)form;
    > > sess=obj.getUser();
    > > HttpSession session=req.getSession();
    > > session.setAttribute("usersession",form);

    >
    > > and in the forwarded jsp page i want to print the values of the
    > > map....

    >
    > > please help....

    >
    > Here's an example using Struts tags.
    >
    > <bean:define name="myRequestScopedBean" property="theMap" id="myMap"/>
    > <logic:iterate id="mapEntry" name="myMap" >
    > <bean:write name="mapEntry" property="key"/> <bean:write
    > 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
    chandan, Apr 10, 2007
    #9
  10. vyshu

    Tim B Guest

    "vyshu" <> wrote in message
    news:...
    > On Apr 10, 1:46 am, "Tim B" <> wrote:
    > > "vyshu" <> wrote in message
    > >
    > > news:...
    > >
    > >
    > >
    > >
    > >
    > > > hi,
    > > > i am confused about iterating through a map in struts.
    > > > i hav a form bean LoginForm.and a getter mathod getID(),which returns
    > > > the values of a map if passed the key as parameter....my code..
    > > > /*public String getId(String key)
    > > > {
    > > > return (String)mapelements(key);
    > > > }
    > > > public Object mapelements(String key)
    > > > {
    > > > Map x=new HashMap();
    > > > x.put("1","vaisahk");
    > > > x.put("2","jovin");
    > > > x.put("3","praveen");
    > > > x.put("4","subhash");
    > > > return x.get(key);
    > > > }
    > > > */
    > > > now i want to print this in the jsp page where i am fowarding from
    > > > here..
    > > > this is my action code..
    > > > LoginForm obj=(LoginForm)form;
    > > > sess=obj.getUser();
    > > > HttpSession session=req.getSession();
    > > > session.setAttribute("usersession",form);

    > >
    > > > and in the forwarded jsp page i want to print the values of the
    > > > map....

    > >
    > > > please help....

    > >
    > > Here's an example using Struts tags.
    > >
    > > <bean:define name="myRequestScopedBean" property="theMap" id="myMap"/>
    > > <logic:iterate id="mapEntry" name="myMap" >
    > > <bean:write name="mapEntry" property="key"/> <bean:write
    > > name="mapEntry" property="value"/>
    > > </logic:iterate>- Hide quoted text -
    > >
    > > - 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?


    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
    > 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.
    >

    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.
    Tim B, Apr 10, 2007
    #10
  11. vyshu

    vyshu Guest

    On Apr 10, 9:07 am, "chandan" <> wrote:
    > On Apr 10, 1:46 am, "Tim B" <> wrote:
    >
    >
    >
    >
    >
    > > "vyshu" <> wrote in message

    >
    > >news:...

    >
    > > > hi,
    > > > i am confused about iterating through a map in struts.
    > > > i hav a form bean LoginForm.and a getter mathod getID(),which returns
    > > > the values of a map if passed the key as parameter....my code..
    > > > /*public String getId(String key)
    > > > {
    > > > return (String)mapelements(key);
    > > > }
    > > > public Object mapelements(String key)
    > > > {
    > > > Map x=new HashMap();
    > > > x.put("1","vaisahk");
    > > > x.put("2","jovin");
    > > > x.put("3","praveen");
    > > > x.put("4","subhash");
    > > > return x.get(key);
    > > > }
    > > > */
    > > > now i want to print this in the jsp page where i am fowarding from
    > > > here..
    > > > this is my action code..
    > > > LoginForm obj=(LoginForm)form;
    > > > sess=obj.getUser();
    > > > HttpSession session=req.getSession();
    > > > session.setAttribute("usersession",form);

    >
    > > > and in the forwarded jsp page i want to print the values of the
    > > > map....

    >
    > > > please help....

    >
    > > Here's an example using Struts tags.

    >
    > > <bean:define name="myRequestScopedBean" property="theMap" id="myMap"/>
    > > <logic:iterate id="mapEntry" name="myMap" >
    > > <bean:write name="mapEntry" property="key"/> <bean:write
    > > 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- Hide quoted text -
    >
    > - 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.
    vyshu, Apr 10, 2007
    #11
  12. vyshu

    vyshu Guest

    On Apr 10, 9:19 am, "Tim B" <> wrote:
    > "vyshu" <> wrote in message
    >
    > news:...
    >
    >
    >
    >
    >
    > > On Apr 10, 1:46 am, "Tim B" <> wrote:
    > > > "vyshu" <> wrote in message

    >
    > > >news:...

    >
    > > > > hi,
    > > > > i am confused about iterating through a map in struts.
    > > > > i hav a form bean LoginForm.and a getter mathod getID(),which returns
    > > > > the values of a map if passed the key as parameter....my code..
    > > > > /*public String getId(String key)
    > > > > {
    > > > > return (String)mapelements(key);
    > > > > }
    > > > > public Object mapelements(String key)
    > > > > {
    > > > > Map x=new HashMap();
    > > > > x.put("1","vaisahk");
    > > > > x.put("2","jovin");
    > > > > x.put("3","praveen");
    > > > > x.put("4","subhash");
    > > > > return x.get(key);
    > > > > }
    > > > > */
    > > > > now i want to print this in the jsp page where i am fowarding from
    > > > > here..
    > > > > this is my action code..
    > > > > LoginForm obj=(LoginForm)form;
    > > > > sess=obj.getUser();
    > > > > HttpSession session=req.getSession();
    > > > > session.setAttribute("usersession",form);

    >
    > > > > and in the forwarded jsp page i want to print the values of the
    > > > > map....

    >
    > > > > please help....

    >
    > > > Here's an example using Struts tags.

    >
    > > > <bean:define name="myRequestScopedBean" property="theMap" id="myMap"/>
    > > > <logic:iterate id="mapEntry" name="myMap" >
    > > > <bean:write name="mapEntry" property="key"/> <bean:write
    > > > name="mapEntry" property="value"/>
    > > > </logic:iterate>- Hide quoted text -

    >
    > > > - 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?

    >
    > 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
    > > 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.

    >
    > 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.- Hide quoted text -
    >
    > - 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, Apr 10, 2007
    #12
  13. vyshu

    vyshu Guest

    Cheers!!!!!!!!!!!
    i got it!!!!
    Thank you so much for helping me.
    vysh.
    vyshu, Apr 10, 2007
    #13
  14. vyshu

    vyshu Guest

    On Apr 10, 1:46 am, "Tim B" <> wrote:
    > "vyshu" <> wrote in message
    >
    > news:...
    >
    >
    >
    >
    >
    > > hi,
    > > i am confused about iterating through a map in struts.
    > > i hav a form bean LoginForm.and a getter mathod getID(),which returns
    > > the values of a map if passed the key as parameter....my code..
    > > /*public String getId(String key)
    > > {
    > > return (String)mapelements(key);
    > > }
    > > public Object mapelements(String key)
    > > {
    > > Map x=new HashMap();
    > > x.put("1","vaisahk");
    > > x.put("2","jovin");
    > > x.put("3","praveen");
    > > x.put("4","subhash");
    > > return x.get(key);
    > > }
    > > */
    > > now i want to print this in the jsp page where i am fowarding from
    > > here..
    > > this is my action code..
    > > LoginForm obj=(LoginForm)form;
    > > sess=obj.getUser();
    > > HttpSession session=req.getSession();
    > > session.setAttribute("usersession",form);

    >
    > > and in the forwarded jsp page i want to print the values of the
    > > map....

    >
    > > please help....

    >
    > Here's an example using Struts tags.
    >
    > <bean:define name="myRequestScopedBean" property="theMap" id="myMap"/>
    > <logic:iterate id="mapEntry" name="myMap" >
    > <bean:write name="mapEntry" property="key"/> <bean:write
    > name="mapEntry" property="value"/>
    > </logic:iterate>- Hide quoted text -
    >
    > - 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.
    vyshu, Apr 10, 2007
    #14
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gogo
    Replies:
    1
    Views:
    2,076
    Sudsy
    Sep 4, 2003
  2. thenrick
    Replies:
    0
    Views:
    1,216
    thenrick
    Sep 23, 2003
  3. runescience
    Replies:
    0
    Views:
    1,430
    runescience
    Feb 9, 2006
  4. Replies:
    3
    Views:
    486
    red floyd
    Sep 13, 2006
  5. John
    Replies:
    4
    Views:
    890
    RedGrittyBrick
    Apr 1, 2008
Loading...

Share This Page