Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring mvc: cleanest way for more than one submit button?

Tags:

spring-mvc

I have a a form and I'd like a next and back button inside it. What is the cleanest way to do this in spring mvc? Just give the input type submit a name and value and check for that in my controller?

like image 710
jack Avatar asked Dec 06 '10 12:12

jack


2 Answers

If you use Spring 3, you can distinguish between controller methods using params attribute:

<input type = "submit" name = "next" value = "Next" />
<input type = "submit" name = "back" value = "Back" />

.

@RequestMapping(..., params = "next")
public ModelAndView next(...) { ... }

@RequestMapping(..., params = "back")
public ModelAndView back(...) { ... }
like image 84
axtavt Avatar answered Nov 01 '22 13:11

axtavt


You could do that, yes. Alternatively, don't use true submit buttons. Instead, use vanilla HTML buttons, with attached javascript handlers which later the form's target, and then programmatically submit the form.

Which one is "cleaner" depends on your point of view.

like image 41
skaffman Avatar answered Nov 01 '22 14:11

skaffman