This week's giveaways are in the MongoDB and Jobs Discussion forums. We're giving away four copies of Mongo DB Applied Patterns and 4 resume reviews from Five Year Itch and have the authors/reps on-line! See this thread and this one for details.
Hello,
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 any tips.
Vladimir
Costi Ciudatu
Ranch Hand
Joined: Oct 24, 2006
Posts: 74
posted
0
Have a look at <form:radiobuttons/>
Vladimir Kroupa
Greenhorn
Joined: Dec 26, 2008
Posts: 27
posted
0
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?
Vladimir Kroupa
Greenhorn
Joined: Dec 26, 2008
Posts: 27
posted
0
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[163840]' of bean class [shop.web.COs.ShoppingCartCO]: Value of nested property 'cartMap[163840]' is null. But when I try to access the cartMap[163840] 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.
Costi Ciudatu
Ranch Hand
Joined: Oct 24, 2006
Posts: 74
posted
0
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 ?
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.