Problem binding different object resulted from dropdown selection
Hi everyone,
I have 2 dropdown and some input field on a page. The input fields are binded to the object selected from the second dropdown. The dropdowns also binded using form:select.
The problem is, when I submit the form after changing selection in the second dropdown, the binding process became awkward .
This is because when I supply the command object in formBackingObject, I'm using the object id from the selected item in the second dropdown. So if the selection change (for example, in the previous get request the id was #2, but then the user select an object with id number #4 and then doing a submit), the id passed to formBackingObject would be misleading. Based on the id, formBackingObject should return a completely different object from previous request (#4 instead of #2), but during the binding process, spring would try to bind values that actualy for object with id #2.
I've been tried to workaround this problem by also bind the id of the old object, so that data from the form bind to the correct object. But it's so ugly, and I have to fool spring binder by supplying binded object twice.
Is there any more elegant solution for this problem, or perhaps I should use different request / bind schenario ?
Thanks for the answer |