cancel
Showing results for 
Search instead for 
Did you mean: 

Validation in WDDOBEFORE Action Not Working...

Former Member
0 Kudos

Hello Experts,

                     I have a requirement to validate two fields on a webdynpro view. I have to throw an error message When the user enters the same values in both the Fields. I have written my logic in WDDOBEFOREACTION method of the view to validate the fields. When i kept the break point , I see that it is not stopping until I press the submit Button.  I need the validation to happen before I do the submit Actions, As this action will bring up a new view . I want to validate and if Wrong , It should stay at the same view. I am not sure where i went wrong. Thanks !! in advance.

Code :

DATA: GV_init_emp TYPE string,

       gv_emp      TYPE string.

     DATA lo_nd_lt_status TYPE REF TO if_wd_context_node.

     DATA lo_el_lt_status TYPE REF TO if_wd_context_element.

     DATA ls_lt_status TYPE wd_this->element_lt_status.

     DATA lv_zemp_paf_init TYPE wd_this->element_lt_status-zemp_paf_init.

*   navigate from <CONTEXT> to <LT_STATUS> via lead selection

     lo_nd_lt_status = wd_context->get_child_node( name = wd_this->wdctx_lt_status ).

     lo_el_lt_status = lo_nd_lt_status->get_element( ).

     IF lo_el_lt_status IS INITIAL.

     ENDIF.

*   get single attribute

     lo_el_lt_status->get_attribute(

       EXPORTING

         name `ZEMP_PAF_INIT`

       IMPORTING

         value = lv_zemp_paf_init ).

GV_init_emp = lv_zemp_paf_init.

* Read node for Employee.

   DATA lv_zemp_name TYPE wd_this->element_lt_status-zemp_name.

* navigate from <CONTEXT> to <LT_STATUS> via lead selection

   lo_nd_lt_status = wd_context->get_child_node( name = wd_this->wdctx_lt_status ).

* get element via lead selection

   lo_el_lt_status = lo_nd_lt_status->get_element( ).

   IF lo_el_lt_status IS INITIAL.

   ENDIF.

* get single attribute

   lo_el_lt_status->get_attribute(

     EXPORTING

       name `ZEMP_NAME`

     IMPORTING

       value = lv_zemp_name ).

gv_emp = lv_zemp_name.

IF gv_emp is NOT INITIAL

   AND gv_init_emp is NOT INITIAL.

IF gv_emp EQ gv_init_emp.

  DATA lv_text_e01 TYPE string.

  lv_text_e01 =

    wd_assist->if_wd_component_assistance~get_text( 'E01' ).

*  get message manager

  DATA lo_api_controller     TYPE REF TO if_wd_controller.

  DATA lo_message_manager    TYPE REF TO if_wd_message_manager.

  lo_api_controller ?= wd_this->wd_get_api( ).

  CALL METHOD lo_api_controller->get_message_manager

    RECEIVING

      message_manager = lo_message_manager

      .

*  report message

  CALL METHOD lo_message_manager->report_error_message

    EXPORTING

      message_text              lv_text_e01

      .

ENDIF.

ENDIF.

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Hi Vishnu,

Get the value by using

lo_el_lt_status->get_attribute(

       EXPORTING

         name `ZEMP_PAF_INIT`

       IMPORTING

         value = lv_zemp_paf_init ).

lo_el_lt_status->get_attribute(

     EXPORTING

       name `ZEMP_NAME`

     IMPORTING

       value = lv_zemp_name ).


Once you readed the values you have to find which action you pressed otherwise before action it ill trigger for actions you have to restrict.

data lo_api_controller type ref to if_wd_view_controller.

  data lo_action  type ref to if_wd_action.

  lo_api_controller = wd_this->wd_get_api( ).

  lo_action = lo_api_controller->get_current_action( ).

  if lo_action is bound.

  case lo_action->name.

    when 'action name'.

          write you logic here .

        if you want raise error message here use attribute error message.

    endcase.

endif.

Thanks

Jayaprakash T

Former Member
0 Kudos

wddobeforeaction will be called before the action handler, and simply raising a error message does not stop the WD framework to take the control to the action handler.

In case you need to stop in the wddobeforeaction, then use the method " REPORT_ATTRIBUTE_ERROR_MESSAGE" for a certain attribute present on the screen. After execution of this method, the control flow will terminate and your message will be displayed to the user.

Ashish

Answers (3)

Answers (3)

ramakrishnappa
Active Contributor
0 Kudos

Hi Vishnu,

Whenever there is any action, before reach the event handler of action, WDDOBEFOREACTION( ) method gets called.

Framework automatically restricts to enter into event handler method if any attribute related error messages there.

So, I suggest you to use REPORT_ATTRIBUTE_ERROR_MESSAGE method to raise an error message instead of report_error_message.

Replace your report_error_message method with the below code.


CALL METHOD lo_message_manager->REPORT_ATTRIBUTE_ERROR_MESSAGE

    EXPORTING

      message_text              lv_text_e01

     element = lo_el_lt_status

     attribute_name = 'ZEMP_NAME'.

Now, systems stops to reach SUBMIT event handler method if any error.



If you like to use report_error_message, then as suggested you need to check if any error messages available and then execute the code for navigation.


Hope this helps you.


Regards,

Rama

      .

harsha_jalakam
Active Contributor
0 Kudos

Hi ,

If you want to validate those fields, before Submit Action. Please create an onenter event handler for the second text field and then write the logic for comparing those two fields,either in Onenter or WODOBEFOREACTION.

Regards,

Harsha

former_member184578
Active Contributor
0 Kudos

Hi,


When i kept the break point , I see that it is not stopping until I press the submit Button.  I need the validation to happen before I do the submit Actions, As this action will bring up a new view . I want to validate and if Wrong , It should stay at the same view. 


WDdobeforeaction will be called before an action is triggere. You need to press the button then the dobeforeaction is triggered followed by your action method.


if you want to stop the flow, use report_exception() method of the message manager. OR in your onAction of submit button place the code inside an if condition., if there are no errors then navigate else no.


To check the condition in your onAction submit button,


  DATA lo_api_controller     TYPE REF TO if_wd_controller.

  DATA lo_message_manager    TYPE REF TO if_wd_message_manager.

  lo_api_controller ?= wd_this->wd_get_api( ).

  CALL METHOD lo_api_controller->get_message_manager

    RECEIVING

      message_manager = lo_message_manager.

 

     If lo_message_manager->is_empty( ) = abap_true.

** your code

    Endif.

Hope this helps,

Regards,

Kiran