Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

webdynpro coding

Hi,

I am stuck in the following code:

// Check if date is valid

if (!DateCalculator.isValid(usrDate))

Description of the Error is The method isValid(Date) is undefined for the type StartView.

Please reply.

Former Member
Former Member replied

Implement you own method isValidDate with this code instead of the DateCalculator class:

public boolean isValidDate(String date)
{
   // set date format, this can be changed to whatever format
   // you want, MM-dd-yyyy, MM.dd.yyyy, dd.MM.yyyy etc.
  
   SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
   
   Date testDate = null;

   // we will now try to parse the string into date form
   try
   {
     testDate = sdf.parse(date);
   }
  catch (ParseException e)
   {
     errorMessage = "the date you provided is in an invalid date" +
                             " format.";
     return false;
   }



   if (!sdf.format(testDate).equals(date))
   {
     errorMessage = "The date that you provided is invalid.";
     return false;
   }
   
   // if we make it to here without getting an error it is assumed that
   // the date was a valid one and that it's in the proper format

   return true;

} 

Regards,

Martin

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question