Reputation: 16661
I have a controller like follows
@Controller
public class SettingsController {
@RequestMapping(value="/editname",method=RequestMethod.POST)
public void editName(@RequestParam(value="firstname") String firstname,
@RequestParam(value="lastname") String lastname) {
final Object principal =
SecurityContextHolder.getContext().getAuthentication().getPrincipal();
try {
jdbcPersonRepository.updateName(principal.toString(), firstname, lastname);
} catch (SignInNotFoundException e) {
}
}
}
and I have my ajax form submit.
$(function() {
//twitter bootstrap script
$("button#submit").click(function(){
var $form = $(this).closest("form");
var type = $form.attr('method');
$.ajax({
type: $form.attr('method'),
url: $form.attr('action'),
data: $form.serialize(),
dataType : "json",
success: function(msg){
$("#thanks").html(msg)
$("#form-content").modal('hide');
},
error: function(){
//alert("failure");
}
});
});
});
and my twitter bootstrap model which has a form which triggers the ajax is as follows
<!-- Name Edit div -->
<div id="form-content" class="modal hide fade in" tabindex="-1">
<form name="edit-form" action="<c:url value="/editname" />" method="post">
<div class="modal-header">
<h4>Edit Name</h4>
</div>
<div class="modal-body">
<div class="control-group">
<div class="controls">
<ul class="nav nav-list">
<li class="nav-header">First Name</li>
<li><input type="text" placeholder="First Name" name="firstName" id="firstName" class="input-xlarge help-inline"></li>
<li class="nav-header">Last Name</li>
<li><input type="text" placeholder="Last Name" name="lastName" id="lastName" class="input-xlarge help-inline"></li>
</ul>
</div>
</div>
</div>
<div class="modal-footer">
<button id="submit" class="btn btn-success">Update</button>
<button class="btn" data-dismiss="modal" >Close</button>
</div>
</form>
</div>
Does any anybody have a clue regarding this error. ?
Upvotes: 1
Views: 5890
Reputation: 718826
In the method declaration, the @RequestMapping
annotations give the parameter names as firstname
and lastname
. In the form HTML they are firstName
and lastName
.
Request parameter names are case sensitive ... ergo, they don't match, and Spring tells you this is an invalid request because mandatory parameters are missing.
Upvotes: 4