This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I have a problem with dynamic forms in Spring 2.5 that I was unable to solve myself.
I have a collection of Items. I would like to display a page that has an input form with submit button next to each Item.
Something like this:
I cannot use a single command object with fields for each Item. Would it be possible to use a Map inside the command object and bind it somehow to the form:input tags?
Thanks for the reply.
I've checked the documentation for <form:radiobuttons> and <form:checkboxes> and I've only found this:
In the case where you use a Map, the map entry key will be used as the value and the map entry's value will be used as the label to be displayed. Could you please tell me a little more about what should I be looking for?
Joined: Dec 26, 2008
I was able to bind the map in a way that works for displaying the map values in a form (GET). However, the binding doesn't work when I try to submit the form.
When I try to submit, I get NullValueInNestedPathException: Invalid property 'cartMap' of bean class [shop.web.COs.ShoppingCartCO]: Value of nested property 'cartMap' is null. But when I try to access the cartMap entry directly in JSP, it works.
This is what my JSP file looks like:
The controller code should be OK:
I'll be grateful for any tips. I have a book on Spring and I've searched the documentation, but I haven't find anything that would help.
Joined: Oct 24, 2006
Let me first try to clarify your issue just to make sure I got the point:
1) You want to be able to update single values in that list of products.
If so, you should consider creating a form instance for every element item; otherwise, every update button will send all the items and their values to the server. In other words, every "Update" button will just behave like a single "Update All" button.
2) You don't actually need a map there, a mere list would be enough (you have the ID as a property of that bean, so you don't need to store it in a map key). Not to mention that HashMap does not guarantee the order of the elements.
3) It looks like you have an empty command object instantiated on submit, with a null cartMap reference. How do you define that CO as command object for your controller ? You may need to initialize the cartMap in the command object's constructor. Can you post the whole code for the controller (especially the submit handler) and probably the spring descriptors ?