This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem while using Map in ActionForm

 
ram gaurav
Ranch Hand
Posts: 208
  • 0
  • Mark post as helpful
  • send pies
  • 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;
}
 
Jass Singh
Ranch Hand
Posts: 52
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So sir please tell me the proper way to follow which help me to achieve this.

Thanks
Regards
Gaurav
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic