2
I have a web application, basically pure wheel with JSP + Angularjs.
The template that I use bootstrap, didn’t have datepicker with Angularjs, so I’m using with jQuery.
I have on my screen, a modal with multiple fields, I could ALREADY pass all data through a POST request with AJAX to my Java controller, made no mistakes.
When I added datepicker, it started to give error 400. What I realized is that the date is being passed to my java controller as mm/dd/yyyy
.
I made the deal with the option format
of datepicker, before sending the dates to the POST is executed.
What I’ve already done:
format
of datepicker already being set asdd/mm/yyyy
andpt_BR
, still no funf.- I have already checked my DTO to see if what is being passed in the request has the same type (
DATE
in the case). - I checked my Imports, as I saw in some posts related attention to the import sequence.
Guys, I don’t know what else to do, it seems so simple. If you need to post more code, just talk. .
BoxApp.controller("UsuariosController", function($scope, $http) {
$scope.usuarios={};
$scope.usuariosParaAlterar={};
$scope.iniciar = function() {
$http.get('/boxmlV2/usuario').success(function (response) {
$scope.usuarios = response;
});
};
$scope.iniciar();
$scope.setSelected = function(selecao){
$scope.usuariosParaAlterar = selecao;
};
/**
* Trecho para validar o form ao submeter.
*/
$scope.submitted = false;
$scope.submitForm = function(formUsuarios) {
$scope.submitted = true;
if (formUsuarios.$valid) {
$("#dataValidadeConta").datepicker({
format: 'dd/mm/yyyy',
language: 'pt-BR'
});
$("#dataValidadeSenha").datepicker({
format: 'dd/mm/yyyy',
language: 'pt-BR'
});
$scope.editaUsuario();
}
};
$scope.editaUsuario = function() {
$http.post('/boxmlV2/usuario/salvarUsuario', {
ativo : $scope.usuariosParaAlterar.ativo,
idUsuario : idUsuario.value,
nome : nome.value,
senha : senha.value,
email : email.value,
bloqueado : $scope.usuariosParaAlterar.bloqueado,
dataValidadeConta : $scope.usuariosParaAlterar.dataValidadeConta,
dataValidadeSenha : $scope.usuariosParaAlterar.dataValidadeSenha,
resetSenha : $scope.usuariosParaAlterar.resetSenha,
perfil : $scope.usuariosParaAlterar.perfil
}).then(function(response) {
$scope.sucesso();
}, function(response) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
};
$scope.sucesso = function() {
$scope.closeMyPopup();
$scope.iniciar();
};
$scope.closeMyPopup = function() {
$(myModal_autocomplete).modal('hide');
};
});
<div class="form-group">
<label class="control-label col-md-3">Data Validade Conta:<span
class="required" aria-required="true"> * </span></label>
<div class="col-md-9">
<input
class="form-control form-control-inline input-medium date-picker"
name="dataValidadeConta" id="dataValidadeConta"
ng-model="usuariosParaAlterar.dataValidadeConta" size="16"
type="text" value="" required /> <span class="help-block">
Selecione a data </span> <span style="color: red"
ng-show="submitted && form.dataValidadeConta.$error.required">Campo
Data Validade Conta Obrigatório.</span>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3">Data Validade Senha:<span
class="required" aria-required="true"> * </span></label>
<div class="col-md-9">
<input
class="form-control form-control-inline input-medium date-picker"
ng-model="usuariosParaAlterar.dataValidadeSenha"
name="dataValidadeSenha" id="dataValidadeSenha" size="16" type="text"
value="" required /> <span class="help-block"> Selecione a
data </span> <span style="color: red"
ng-show="submitted && form.dataValidadeSenha.$error.required">Campo
Data Validade Senha Obrigatório.</span>
</div>
</div>
Java Controller:
@Controller
public class CadastroUsuariosController {
@Autowired
private UsuarioService usuarioService;
@RequestMapping(value="/usuario", method=RequestMethod.GET)
public ModelAndView iniciar(ModelMap modelMap){
return new ModelAndView("usuario");
}
@RequestMapping(value="/usuario",method=RequestMethod.GET,produces={"application/json"})
public @ResponseBody List<UsuarioDTO> obterTodos(ModelMap modelMap){
return usuarioService.obterTodos();
}
@RequestMapping(value = "/usuario/salvarUsuario", method = RequestMethod.POST, produces = { "application/json" })
public @ResponseBody RetornoDTO insereOuEditaUsuario(
@RequestBody UsuarioDTO usuarioDTO) {
usuarioService.insereOuEditaUsuario(usuarioDTO);
return new RetornoDTO(RetornoEnum.SUCESSO);
}
}
Thank you for the reply, I will apply and return...
– Leonardo Leonardo
Luiz, just one question, there in my JS I’m making the conversion to go to my controller. You know why it doesn’t work? Please, I don’t understand pq.. was also trying to force in the header of the en-BR header in Accept-Language
– Leonardo Leonardo
@Eonardo All you need to do is order and receive in the same format. Regardless of which format is sent by javascript, use it on the server and everything will be fine. No need to worry about the location.
– utluiz