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?
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
Joined: Dec 21, 2012
Posts: 3
posted
0
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.
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.