Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mapbacked forms

 
Balbir Singh
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using map-backed forms for generating dynamic views. The concept goes like this that one jsp constitues of defined no of views, some of the views are static and some are dynamic, each view is made up of a value object, which is a form. The dynamic views are populated by using maps. So if i used map-backed forms for static pages, it works fine but for dynamic views, i have to use a map inside a map. The code for actionform eg looks like this :
public class TestForm extends ActionForm {
private Map values = new HashMap();
Map testMap = new HashMap();

public TestForm() {
super();
}

public void setValue(String key, Object value) {

values.put(key, value);

}
public Object getValue(String key) {
return values.get(key);

}
public void reset(ActionMapping arg0, HttpServletRequest arg1) {

testMap.put("testField", "Why can't I populate it");
values.put("testMap", testMap);
values.put("retest", "Retest String");

}
public ActionErrors validate(ActionMapping arg0, HttpServletRequest arg1) {

return super.validate(arg0, arg1);
}
}
the jsp code is

<TABLE border="0" width="497">
<TBODY>
<TR>
<TD width="101">Test</TD>
<TD width="388">

<html:text property="value(testMap).testField"></html:text>
</TR>
<TR>
<TD width="101">Reset</TD>
<TD width="388">
<html:text property="value(retest)"></html:text>
</TR>
</TBODY>
</TABLE>

but when I enter a value in the jsp and press submit, then only the value for the second field is dynamically filled by the form, but not for the first field (which is actually a field of a map inside a map). Is there any way i can use nested map-backed forms, i guess it should work since its able to get the values in the jsp using nested map, so it should also set the values as such. I am not sure what i m doing wrong over here ?
I will really appreciate your help in this.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic