cancel
Showing results for 
Search instead for 
Did you mean: 

Override standard date validation

Former Member
0 Kudos

Hi,

I have an Input Field bound to an attribute of type date (defined in dictionary with representation as dd/MM/yyyy) in a table.

On Submit, this date format is validated by the framework and a standard error is thrown if the format is different from above.

Is there any way I can override this standard method and print a custom message along with performing some other tasks. I essentially want to retrieve the row index(es) of the concerned rows and use them for further processing.

Even if I can extract the row index(es) of the concerned rows somehow, it would solve my problem Giving a custom mesaage is not all that important.

SAP NetWeaver Developer Studio Version: 7.02.06

Thanks,

Himanshu

Accepted Solutions (1)

Accepted Solutions (1)

saravanan_narayanan
Active Contributor
0 Kudos

Hello Himashu,

Once the validation error happens, after exeucting BeforeAction method, the control goes to component's before navigation method. here you can check in message manager whether it has validation errors. if so then you can clear the already raised message and populate your own message.

Kindly note here you can play around only with the message text. you cant influence the control flow.

BR, Saravanan

Former Member
0 Kudos

Thanks Saravanan,

Can you also suggest how to clear the raised message.

Thanks,

Himanshu

Former Member
0 Kudos

Hi Himanshu,

As suggested by sarvanana remove the standard IWD Message and keeping the custom message :

public void wdDoBeforeAction(com.sap.tc.webdynpro.progmodel.api.IWDBeforeAction validation)
  {
    //@@begin wdDoBeforeAction
	  IWDMessageManager msgMgr  = wdComponentAPI.getMessageManager();
	  if(msgMgr.hasExceptions()){
	  msgMgr.removeMessage(msg);
                   //custom message
	  msgMgr.reportSuccess("Please enter a valid date in this format:"+"dd/MM/yyyy");
	  }
    //@@end
  }

//declare IWDMessage in begin others

//@@begin others
  IWDMessage msg;
  //@@end

Hope this helps.

Regards,

Saleem Mohammad.

Former Member
0 Kudos

Thanks Saleem ,

However it looks like this API is not supported in my version of NWDS (Version: 7.02.06).

Maybe the higher versions have this API.

Regards,

Himanshu

Former Member
0 Kudos

Hi Himanshu,

If you are using CE 7.1 then you can apply this, but your NWDS version doesn't support this API method.

so please go with a manual validation and if you feel your question is answered please close the thread.

Regards,

Saleem Mohammad.

Former Member
0 Kudos

Thanks Everyone.

I think I will have to live with the standard mesage.

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Himanshu,

As john said it is not possible to skip the standard validation thrown by webdynpro framework.

You can do a manual validation without binding the context value attribute to a dictionary type using SimpleDateFormat.

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

    // try to parse the string into date form
    try
    {
      testDate = sdf.parse(date);
    }

    // if the format of the string provided doesn't match the format we 
    // declared in SimpleDateFormat() we will get an exception

    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;
    }
    
      return true;

} // end isValidDate

Hope this helps you.

Regards,

Saleem Mohammad.

junwu
Active Contributor
0 Kudos

i don't think it is possible

what you can do is disable the validation, you have to validate all the data manually by your own code.