Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Storing changes in form backed object

  1. #1

    Default 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. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    Can you show us the jsp/controller/configuration.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3

    Default

    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

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    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.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5

    Default

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

  6. #6

    Default

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

  7. #7
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    You also might need to change the id field to ${status.expression}.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  8. #8

    Default

    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 at 05:33 AM.

  9. #9
    Join Date
    Sep 2004
    Location
    Manchester, NH
    Posts
    1,236

    Default

    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.
    Peter Mularien | Blog
    Author, Spring Security 3 (Book) - Packt Publishing, Available in print and eBook form
    SCJP 5, Oracle DBA
    Any postings are my own opinion, and should not be attributed to my employer or clients.


  10. #10

    Default

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •