Search code examples
javajspatgatg-dynamo

How can I get Date field from the JSP page to repositoryFormHandler?


I have created a JSP which has input field for date which accepts date like 1987-12-16

<dsp:input bean="RegisterFormHandler.dob" date="yyyy-MM-dd" size="25" type="text" required="true" />

and I am trying to set the value in RepositoryFormHandler

public void setDob(SimpleDateFormat dob) 
{
    this.dob = dob;
}

but set property is not calling the above function, I am not sure what is the problem here.


Solution

  • Your problem is that you are trying to call setDob(SimpleDateFormat dob) where what you meant was setDob(Date dob). You are not passing the format but the actual date.

    That said, I've seen numerous examples in ATG when trying to pass the date in via a free-text field that ends up with unnecessary errors in the back end, even when you pass the 'date' format along. Most implementations, that work, will format the date with something like the jQuery DatePicker library and pass it to ATG as a String value. In your formhandler you then implement a validation method that will parse the String for being a valid date and return the appropriate exception. Your approach above is fraught with danger.