Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

218
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda