aspose file tools*
The moose likes Struts and the fly likes Problem while using Map in ActionForm Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Problem while using Map in ActionForm" Watch "Problem while using Map in ActionForm" New topic
Author

Problem while using Map in ActionForm

ram gaurav
Ranch Hand

Joined: Mar 29, 2006
Posts: 208
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;
}
Jass Singh
Ranch Hand

Joined: Mar 30, 2006
Posts: 52
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

Joined: Mar 29, 2006
Posts: 208
So sir please tell me the proper way to follow which help me to achieve this.

Thanks
Regards
Gaurav
 
 
subject: Problem while using Map in ActionForm