Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
  • 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

Problem while using Map in ActionForm

 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI

I want to use Map in my AcionMap class.What i have written is :

In JSP file:
<html:text property="value(name)"/>

In ActionForm class:
Map map = null;
public Object getValue(String key)
{
return map.get(key);
}

public void setValue(String key , String value)
{
map.put(key , value);
}

public Map getMap() {
return map;
}

and in Action class i write:
String name = (String)testForm.getValue("name");

but now at this place 'name' is coming to be null.
What mistake i am making.

Thanks
Regards
Gaurav

public void setMap(Map map) {
this.map = map;
}
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by ram gaurav:
HI

I want to use Map in my AcionMap class.What i have written is :

In JSP file:
<html:text property="value(name)"/>




Above syntax is wrong. in property attribute you can not specify argument along with method/property name.




In ActionForm class:
Map map = null;
public Object getValue(String key)
{
return map.get(key);
}

public void setValue(String key , String value)
{
map.put(key , value);
}

public Map getMap() {
return map;
}

and in Action class i write:
String name = (String)testForm.getValue("name");

but now at this place 'name' is coming to be null.
What mistake i am making.



Again you can not have getter methods with parameters in form bean. And setter method should have only one parameters. I mean you can have them in any format but for struts to invoke using reflection, these methods have to be in above mentioned format only.

Advisable solution would be to get map object using getMap() and then call get() on this map object.

Regards
Jass
 
ram gaurav
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So sir please tell me the proper way to follow which help me to achieve this.

Thanks
Regards
Gaurav
reply
    Bookmark Topic Watch Topic
  • New Topic