java_dude
java_dude

Reputation: 4088

Two submits in one JPS and two actions in Spring

I know this question has been asked and answered but I don`t seems to have found a solution.

<form:form method="post" action="my.htm" modelAttribute="someForm">
    <div class="rightAlign"><input type="submit" value="something" name="something"/></div>
    <div class="rightAlign"><input type="submit" value="delete" name="delete"/></div>
</form:form>

How should I map it in controller?

 @RequestMapping(method = RequestMethod.POST, params="/delete")

or

 @RequestMapping(method = RequestMethod.POST, value="/something")

Upvotes: 0

Views: 55

Answers (1)

kryger
kryger

Reputation: 13181

Form's action corresponds to RequestMapping's value parameter, name of the input field will be used as the name of the HTTP parameter, use the params element to "catch" it. The correct RequestMapping configuration to filter by form's content would be:

@RequestMapping(value="my.htm", method=RequestMethod.POST, params="delete")

and

@RequestMapping(value="my.htm", method=RequestMethod.POST, params="something")

(It's all in the documentation)

Upvotes: 3

Related Questions