• 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
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to create forms in a loop in Spring MVC

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a list of data picked from mysql and I am presenting it in a loop in jsp using Spring MVC framework. Each loop has its own form (like in facebook posts).



Now the question is how to handle each form? For the page carrying above code, the controller is:



If there would be only one form, addFeed would be called. But how to manage here? Can anyone suggest me anything?
 
Ranch Hand
Posts: 530
Hibernate Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't understand why you need that? I think there is only a form submitted at a time so there is no need to check which form.
In case you have a good reason to use, I suggest you to use a hidden field in the form and in the controller you can check value of that field.
 
Honey Agarwal
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nam Ha Minh wrote:I don't understand why you need that? I think there is only a form submitted at a time so there is no need to check which form.
In case you have a good reason to use, I suggest you to use a hidden field in the form and in the controller you can check value of that field.



Thanks...that worked but I have to use new form for every loop for that to work otherwise I will get id or any hidden value of the first post.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, but that is not the correct way to display a list of Links or buttons where each is for an "id" that you want to pass. You definitely do not want a form tag for each row in that list.

Personally, I like just having them as links where the id is added to the URL either as a path variable or as a request parameter. Then I use CSS to make the link look like a button. The link would then do a get instead of a post.

If you still want buttons, I would still set the button's action to include the id of that row as a request parameter.

Then your controller method is mapped to one single method which takes in the @RequestParam("nameOfParamHere") or @PathVariable.

Mark
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic