Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

216
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!