Upgrading to struts 2.3.15.1 does not set HashMap values on action class

后端 未结 2 1305
旧巷少年郎
旧巷少年郎 2021-01-14 15:55

I upgraded from 2.1.6 to 2.3.15.1 because of the security fixes available in the latest version. However, now the form field values are not posted to the Action class. Basi

2条回答
  •  清酒与你
    2021-01-14 16:43

    There have been huge changes since Struts 2.1.6. Struts 2 will not create objects for you if you don't explicitly tell it to do. The prepare method calls before the params interceptor sets props to the action, and you commented that you populate the map

    //fill up props map here.

    not surprisingly, that Struts not call that setter setProps because it already contains a map instance. So, it simply calls getProps. Then it should set the indexed property values to the map. But it doesn't know a type of the object that is an element of the collection to convert to, and if it should create a new object for element if it's null. By putting annotations on the props field it should solve the problem populating a map on submit.

    @Element(value = Wall.class)
    @CreateIfNull(value = true)
    private Map props = new HashMap<>();
    

    I guess the key it will determine automatically. The same could be done if you specify it in Action-conversion.properties

    Element_props=Wall
    CreateIfNull_props=true
    

    Next your JSP could be replaced to

    
        
    
    

    And last the Wall class you haven't posted, should look like

    public class Wall {
      String value;
      //getter and setter here
    } 
    

提交回复
热议问题