Announcement Announcement Module
Collapse
No announcement yet.
Storing changes in form backed object Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Storing changes in form backed object

    I have an object created and bound to the form using the formBackingObject method. In the JSP the relevant form fields are surrounded by the spring:bind tag.
    The view is displayed with the proper values and I can edit them. But when submitting the changes to the server they get lost and the successView results in the values I had before doing the changes.

    What do I have to do to persist the changes and make them visible in the JSP/view?

    Thank you
    Dirk

  • #2
    Can you show us the jsp/controller/configuration.

    Comment


    • #3
      What exactly do youmean with JSP/controller configuration?
      Here's the bean definition in the application contxt XML file as well as the form in the JSP responsible for rendering the data and sending the changes to the server:

      Code:
      Bean definition in application context:
      -------------------------------------------
      <bean id="dbMaintenanceFormController" class="com.siemens.checklist.controller.admin.DbMaintenanceFormController">
      	<property name="successView"><value>redirect:${redirectprefix.url}admin/dbMaintenanceForm.html</value></property>
      	<property name="formView"><value>admin/dbMaintenanceForm</value></property>
      	<property name="sessionForm"><value>false</value></property> <!-- it doesn't matter -->
      	<property name="checklistApplicationManager"><ref bean="checklistApplicationManager"/></property>
      </bean>
      
      The formBackingObject method in the controller:
      ----------------------------------------------
      protected Object formBackingObject(HttpServletRequest request) throws Exception
      {
      	DbMaintenanceContainer dbmc = new DbMaintenanceContainer();
      	List configurations = checklistApplicationManager
      		.getChecklistConfigurationManager().getConfiguration();
      	List allVirtualUserrights = 
      		checklistApplicationManager.getAllVirtualUserrights();
      	dbmc.setCcItems(configurations);
      	dbmc.setVuItems(allVirtualUserrights);
      	
      	return dbmc;
      }//end formBackingObject
      
      The JSP:
      --------
      <form name="configurationForm" action="" method="post">
      	<display:table name="${command.ccItems}" id="cConfig" uid="configs"
      				requestURI="dbMaintenanceForm.html"
      				class="checklist_table" pagesize="10" 
      	>
      		<!-- The key -->
      		<display:column title="Key" style="width: 100px;">
      			<%--<spring:bind path="command.ccItems[${configs_rowNum-1}].key">
      				<input type="hidden" id="configKey_${configs_rowNum-1}" name="configKey_${configs_rowNum-1}" value="${status.value}" size="30"/>--%>
      				<c:out value="${ command.ccItems[configs_rowNum-1].key }"/>
      			<%--</spring:bind>--%>
      		</display:column>
      		
      		<!-- The value -->
      		<display:column title="Value" style="width: 100px;">
      			<spring:bind path="command.ccItems[${configs_rowNum-1}].value">
      				<input type="hidden" id="configOldValue_${configs_rowNum-1}" name="configOldValue_${configs_rowNum-1}" value="${status.value}" size="30"/>
      				<input type="text" id="configValue_${configs_rowNum-1}" name="configValue_${configs_rowNum-1}" value="${status.value}" size="30" readonly="readonly"/>
      			</spring:bind>
      		</display:column>
      		
      		<!-- The edit button -->
      		<display:column  title="Edit" style="width: 50px; text-align:center;">
      			<input type="button" id="configEdit_${configs_rowNum-1}" name="edit" value="edit" style="text-align:center;" 
      					onclick="enableConfigItemModification('configValue_${configs_rowNum-1}', this, 'sendEdit_${configs_rowNum-1}');"/>
      			<input type="submit" style="text-align:center; font-size:115%; font-weight:bold; color:green; display:none;" id="sendEdit_${configs_rowNum-1}" 
      					name="sendEditConfig_${configuration.id}" value="send" 
      					onclick="checkConfigInput('configOldValue_${configs_rowNum-1}', 'configValue_${configs_rowNum-1}');"/>
      		</display:column>
      		
      		<!-- The remove button -->
      		<display:column  title="remove" style="width: 50px;">
      			<input type="submit" name="removeConfigurationItem_${configs_rowNum-1}" value="remove"/>
      		</display:column>
      	</display:table>
      </form
      In the controller I use a helper class called DbMaintenanceContainer which currently holds two lists of distinct objects for the time being. This number of objects will surely increase in the future.
      (In the beginning I used an inner class in the controller but EL was not able to access inner classes (since they are not public).)

      The JSP have forms for each object (list of objects) to be displayed.

      Hope this helps!?

      Regareds
      Dirk

      Comment


      • #4
        First of all setting the sessionForm does matter, it changes the behavior of your controller and the way it handles subsequent requests. I would suggest that you set it to true.

        Your JSP isn't correct. Input field which are surrounded by the Spring bind tag must have as the name ${status.expression} and as the value ${status.value}. Yuo cannot simply put some name in the name value.

        Comment


        • #5
          When changing the sessionForm property from false to true, I get this exception when loading the JSP:
          java.lang.IllegalArgumentException: setAttribute: Non-serializable attribute

          Comment


          • #6
            Changing the input field name to ${status.expression} doesn't change the behaviour. The changes still get lost.

            Comment


            • #7
              You also might need to change the id field to ${status.expression}.

              Comment


              • #8
                I already did so.
                Is the path property correct? Maybe <spring:bind path="command.ccItems[${configs_rowNum-1}].value"> is incorrect?
                command is the DbMaintenanceContainer object.
                ccItems is the list of objects within the DbMaintenanceContainer object to be displayed in the display tag / table.
                The index to access the item/element of the list do I get this way:
                I take the uid property of the display tag (which is 'configs' in my case) and attach '_rowNumber' to it (as described in the displaytag doc). This way I get the current (1-based) row number.
                When accessing the list I subtract 1 since the list is 0-based.
                Last edited by du-it; Apr 3rd, 2007, 05:33 AM.

                Comment


                • #9
                  Since you are not referencing ${status.expression} for the name= attribute on the INPUT fields, Spring is not going to be able to bind back these fields to the same bind paths you're using to display them.

                  Your INPUT name attributes look like this:
                  Code:
                  name="configOldValue_${configs_rowNum-1}"
                  So, configOldValue_1 (for example) is the bind path that Spring will look for on your command object. This is different than the path you're binding with the spring:bind tag. Without seeing your controller and command object, it's hard to say whether this is correct behavior on your part.

                  Comment


                  • #10
                    You're correcting me to use ${status.expression} and ${status.value}.
                    The fact that changes were not persisted was caused by Hibernate which is used. In the responsible hbm.xml the insert and update properties were set to false so that no changes could be stored.

                    Now everything is running well.

                    Thank you very much for your brilliant help.

                    Best regards
                    Dirk

                    Comment


                    • #11
                      hi,

                      I have almost the same issue.. I am using spring 3. I am using annotations and display tags. i had discussed the issue in http://forum.springsource.org/showth...761#post414761 this link. But got no replies yet. Plz help me

                      Comment

                      Working...
                      X