Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

217
Visualizações
Spring Input Type Date error using InitBinder

I'm trying to use @InitBinder for my 2 column in my postgres table:

jsp

<form:input type="date" id="start_date" name="start_date" path="startDate"/>

<form:input type="date" id="expiry_date" name="expiry_date" path="expiryDate"/>

Controller

@InitBinder
public void customizeBinding (WebDataBinder binder) {
    SimpleDateFormat dateFormatter = new SimpleDateFormat("MM/dd/yyyy");
    dateFormatter.setLenient(false);
    binder.registerCustomEditor(Date.class, "startDate",
            new CustomDateEditor(dateFormatter, true));
    binder.registerCustomEditor(Date.class, "expiryDate",
            new CustomDateEditor(dateFormatter, true));
}

@RequestMapping(value = {"/create/add","/home/create/add"}, method = RequestMethod.POST)
public String addContractHeader(@ModelAttribute("contractHeader") ContractHeader p, BindingResult bindingResult, Model model) {
    System.out.println("ENTER");

    this.contractHeaderService.addContractHeader(p);

    return "redirect:/home/create";

}

Model

@Column(name = "start_date")
private Date startDate;

@Column(name = "expiry_date")
private Date expiryDate;

Error

descriptionThe server encountered an internal error that prevented it from fulfilling this request.

exception

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement
root cause

org.hibernate.exception.ConstraintViolationException: could not execute statement
root cause

org.postgresql.util.PSQLException: ERROR: null value in column "start_date" violates not-null constraint
  Detail: Failing row contains (5, dfgdsfsd, dsfdsf, sdfdsfsd, sdfsdfdsf, (888) 888-8888, arnold@yahoo.com, License, Draft, Gold, null, MYR, 4444.01, null, null, test).

Console log

2017-04-26T16:32:50.125+0800|Info: Hibernate: insert into CONTRACT_HEADER (contact_email, contact_number, contact_person, contract_number, contract_package, contract_status, contract_sum, contract_type, currency_type, customer_address, customer_name, expiry_date, package_other, remarks, start_date) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
2017-04-26T16:32:50.126+0800|WARN: SQL Error: 0, SQLState: 23502
2017-04-26T16:32:50.126+0800|ERROR: ERROR: null value in column "start_date" violates not-null constraint
  Detail: Failing row contains (7, qqqqq, qqqq, qqqqqqqq, qqqqqq, (888) 888-8888, arnold@yahoo.com, License, Draft, Gold, null, MYR, 4444.01, null, null, dfdfdfd).

Why is it trying to insert null, null, on my date columns when I already specified 04/26/2017 and 04/30/2017 as an input for both fields?

EDIT:

CustomDateEditor

public CustomDateEditor(DateFormat dateFormat, boolean allowEmpty) {
    this.dateFormat = dateFormat;
    this.allowEmpty = allowEmpty;
    this.exactDateLength = -1;
}
over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda