在 Struts 1 中,我使用了map-backed action form来获取动态字段值。
public MyForm extends ActionForm {
private final Map values = new HashMap();
public void setValue(String key, Object value) {
values.put(key, value);
}
public Object getValue(String key) {
return values.get(key);
}
}
下面是我使用的代码。
JSP
<form action="/SaveAction.do">
<input type="text" name="value(dynamicNames)" value="some value">
</form>
行动
public class SaveAction extends ActionSupport implements ModelDriven<MyForm> {
private MyForm myForm = new MyForm();
@Override
public MyForm getModel() {
return myForm;
}
public void setMyForm(MyForm myForm){
this.myForm = myForm;
}
public MyForm getMyForm(){
return myForm;
}
public String execute(){
MyForm formData = getMyForm();//Here I am getting empty object.
return "SUCCESS";
}
}
形式
public MyForm {
private final Map values = new HashMap();
public void setValue(String key, Object value) {
values.put(key, value);
}
public Object getValue(String key) {
return values.get(key);
}
}
如何在 Struts 2 中实现相同的功能?