I use an AbstractWizardFormController to add price changes to a product. The URL addPriceChange.html is mapped to the controller, and I use a query string (aka "GET") parameter (id=X) to tell the formBackingObject() method what product it should get from the database.
addPriceChange.html?id=1 will start the process of adding a price change to product number 1, etc.
The first page view (i.e. index 0 of the setPages() string array) renders a HTML form with a _target1 parameter in order to send the process to its next stage:
<form method="post">
...
<input type="text" name="${status.expression}" value="${status.value}">
...
<input type="submit" name="_target1">
...
</form>
The form is processed, and all the POSTed <input> fields are bound to the form backing object. So far, so good.
The "problem" is that it seems that the initial id=X GET parameter is also bound to the form backing object, even though I only intended it to be used to initialize the form backing object.
(This happens as the above mentioned <form>, lacking an action="..." attribute, is POSTed to itself, and thus the id=X is still present in the query string part of the URL.)
It took me quite a while to realize that the initial id=X GET parameter in turn was causing a setId() call on the form backing object - and it caused quite a lot of trouble today.I simply didn't realize that query string "GET parameters" was bound in the same way as regular POST parameters in such cases - probably because the progress of an AbstractWizardFormController is otherwise tied to POSTs.
The workaround is obviously to change the <form> in the first (index 0) view to this:
<form method="post" action="addPriceChange.html">
...because then the id=X parameter will not be present in subsequent POSTs.
But my question is: Should it work this way in the first place? Perhaps it really is obvious to most people that query string parameters will be bound in the same way as regular form <input> parameters, but I didn't think of it during the first hour of debugging. :oops:


I simply didn't realize that query string "GET parameters" was bound in the same way as regular POST parameters in such cases - probably because the progress of an AbstractWizardFormController is otherwise tied to POSTs.
Reply With Quote
