Uploaded image for project: '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
    • Status: Closed
    • Priority: 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

        Hide
        newton_dave 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
        newton_dave 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.
        Hide
        lukaszlenart 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
        lukaszlenart 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.

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Development