I have three request param in my method and only if Http POST request body has all three parameters availableCostTypesReturn,selectedCostTypesReturn and costTypeProgramId then only this method is getting called.
Successful POST request Body
availableCostTypesReturn=1&availableCostTypesReturn=2&availableCostTypesReturn=3&
availableCostTypesReturn=4&selectedCostTypesReturn=5&costTypeProgramId=53
Now if my POST request body changes to
availableCostTypesReturn=1&availableCostTypesReturn=2&availableCostTypesReturn=3&
availableCostTypesReturn=4&availableCostTypesReturn=5&costTypeProgramId=53
then this method is not getting invoked.
@RequestMapping(value = "/costTypes", method = RequestMethod.POST)
public String updateCostType(
Model model,
@RequestParam(value="availableCostTypesReturn")
String[] availableCostTypesReturn,
@RequestParam(value="selectedCostTypesReturn")
String[] selectedCostTypesReturn,
@RequestParam(value="costTypeProgramId")
int costTypeProgramId
)
There are scenarios when only one of the availableCostTypesReturn, selectedCostTypesReturn parameter will be present.
Modified my method signature to this
So how can i use the same method for this.
I am using Spring MVC 3.0.x
Modified my annotation signature as per answer from Tomasz Nurkiewicz
@RequestParam(value="availableCostTypesReturn", defaultValue= "", required = false)
Try with
requiredattribute of@RequestParamset tofalse: