• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Dynamic form - multiple form:input tags

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have a look at <form:radiobuttons/>
 
Vladimir Kroupa
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic