This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

Storing changes in form backed object

Apr 2nd, 2007, 01:29 PM

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?

Comment

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:

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).)

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

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.

Comment

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

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

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.