javastruts2strutsstruts1

Struts2 using Struts1-Style Getter/Setter methods for indexed properties


In Struts(1/2) a indexed property in the HTML-Page looks like this: <input type="text" name="myIdxProp[1]" value="foo" />

In Struts 1 the corresponding Getter/Setter-Methods which are called during bean population in the Struts-FormBean (Model) for this indexed properties looked like this:

public void setMyIdxProp(int index, String value){
   // Do something with the value
}
public String getMyIdxProp(int index) {
   String retVal = "" //get the value from somewhere
   return retVal;
}

Struts 2 is working working with Lists (or other Collections) in this way:

public List<String> getMyIdxProp(){
    return this.myIdxProp;
}
public void setMyIdxProp(List<String> myIdxProp){
    this.myIdxProp = myIdxProp;
}

My question: Is there any way how I can teach Struts2 to use Struts1-style bean population for indexed properties?

Maybe some kond of bean population interceptor or filter. The goal would be to be able to use both methods in the end (maybe with some flag to enable/disable the interceptor/filter).

Any hint is appreciated. I really don't know how to achieve this without changing all my StrutsForms.

Background: We have an old Struts1 application which should be revived and migrated to Struts2. The plan is to reuse Actions and Forms as much as possible.


Solution

  • Overwriting the Struts2 ParamsInterceptor did the trick for me.