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

1.6k views Asked by At

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.

2

There are 2 answers

0
radimpe On BEST ANSWER

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.

3
Anshu Kumar On

Yes there are ways, but most of prefer as:

  1. On JSP make a simple input box not desp:input
  2. That inout box must have id or class, using that we set some dsp:input which is hidden in your jsp.
  3. Write jQuery script which make the date as MM/DD/YYYY and set that hidden dsp:input value using jQuery.

Jsp:-/*dsp:input */

<dsp:getvalueof var="dateOfBirth" bean="ProfileFormHandler.value.dateOfBirth" />

/*simple input */

<input type="text" value="${dob}" maxlength="10" class="field text dob" id="accDOB" name="accDOB"></code>

/*jQuery */

    var accDOB = $('#accDOB').val();
    var d = accDOB.split("/");
    var dob = d[1]+'/'+d[0]+'/'+d[2];
    //convert the formate in mm/dd/yy
    $("#dob").val(dob);

Hope this help you.