File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes How to create forms in a loop in Spring MVC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "How to create forms in a loop in Spring MVC" Watch "How to create forms in a loop in Spring MVC" New topic
Author

How to create forms in a loop in Spring MVC

Honey Agarwal
Greenhorn

Joined: Dec 21, 2012
Posts: 3
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?
Nam Ha Minh
Ranch Hand

Joined: Oct 31, 2011
Posts: 498

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.


PM Me If You Want to get Urgent Help on Java Programming
Honey Agarwal
Greenhorn

Joined: Dec 21, 2012
Posts: 3
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.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to create forms in a loop in Spring MVC