Struts 2
  1. Struts 2
  2. WW-3825

Struts2 (modeldriven) update method setting fields which do not exist on form to null

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Not a Problem
    • Affects Version/s: 2.3.1.2
    • Fix Version/s: 2.3.8
    • Component/s: None
    • Labels:
      None

      Description

      Struts 2 sets the fields values to Null, if it doesn't exists on view/jsp.

      See below link.

      http://forums.devshed.com/java-help-9/struts2-modeldriven-update-method-setting-fields-which-do-not-exist-642900.html

      I am forced to put all non view fields as HIDDEN on JSP page, to have it values transferred.

      Is there a way to retain the values of non form fields without using HIDDEN.

        Activity

        Sam created issue -
        Hide
        Dave Newton added a comment -

        If the model isn't in session, it's going to create a new model instance, and however fields that aren't on the form are initialized is what will be in the model.

        If you using a persistent object directly, then your code needs to take that in to account, how to do so depends on the persistence mechanism you're using.

        Show
        Dave Newton added a comment - If the model isn't in session, it's going to create a new model instance, and however fields that aren't on the form are initialized is what will be in the model. If you using a persistent object directly, then your code needs to take that in to account, how to do so depends on the persistence mechanism you're using.
        Lukasz Lenart made changes -
        Field Original Value New Value
        Fix Version/s 2.3.7 [ 12323448 ]
        Lukasz Lenart made changes -
        Fix Version/s 2.3.8 [ 12323480 ]
        Fix Version/s 2.3.7 [ 12323448 ]
        Hide
        Lukasz Lenart added a comment -

        As Dave mentioned that's how the framework works. It will create an instance of Model with default constructor. If you want to avoid that, load your model from backend with Preparable interface, then only fields presented in request (from form) will be changed.

        Show
        Lukasz Lenart added a comment - As Dave mentioned that's how the framework works. It will create an instance of Model with default constructor. If you want to avoid that, load your model from backend with Preparable interface, then only fields presented in request (from form) will be changed.
        Lukasz Lenart made changes -
        Status Open [ 1 ] Closed [ 6 ]
        Assignee Lukasz Lenart [ lukaszlenart ]
        Resolution Not A Problem [ 8 ]

          People

          • Assignee:
            Lukasz Lenart
            Reporter:
            Sam
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development