BAEL-3820: Multiple submit button to a Form (#10457)

This commit is contained in:
sampada07
2021-01-31 23:09:23 +05:30
committed by GitHub
parent 51b6942066
commit 695bd40b3f
2 changed files with 10 additions and 2 deletions

View File

@@ -26,7 +26,7 @@ public class EmployeeController {
return employeeMap.get(Id);
}
@RequestMapping(value = "/addEmployee", method = RequestMethod.POST)
@RequestMapping(value = "/addEmployee", method = RequestMethod.POST, params = "submit")
public String submit(@Valid @ModelAttribute("employee") final Employee employee, final BindingResult result, final ModelMap model) {
if (result.hasErrors()) {
return "error";
@@ -37,5 +37,11 @@ public class EmployeeController {
employeeMap.put(employee.getId(), employee);
return "employeeView";
}
@RequestMapping(value = "/addEmployee", method = RequestMethod.POST, params = "cancel")
public String cancel(@Valid @ModelAttribute("employee") final Employee employee, final BindingResult result, final ModelMap model) {
model.addAttribute("message", "You clicked cancel, please re-enter employee details:");
return "employeeHome";
}
}

View File

@@ -7,6 +7,7 @@
</head>
<body>
<h3>Welcome, Enter The Employee Details</h3>
<h4>${message}</h4>
<form:form method="POST" action="${pageContext.request.contextPath}/addEmployee" modelAttribute="employee">
<table>
@@ -23,7 +24,8 @@
<td><form:input path="contactNumber" /></td>
</tr>
<tr>
<td><input type="submit" value="Submit" /></td>
<td><input type="submit" name="submit" value="Submit" /></td>
<td><input type="submit" name="cancel" value="Cancel" /></td>
</tr>
</table>
</form:form>