cancel
Showing results for 
Search instead for 
Did you mean: 

Web Dynpro implementing check for required fields in a table ?

Former Member
0 Kudos

When I set the property in a table cell editor to required you can still proceed with actions/navigation without entering any value in those fields. Is there a standard way to perform these checks or should it be coded in WDDOBEFOREACTION manually?

Accepted Solutions (1)

Accepted Solutions (1)

former_member206396
Active Participant

Hi,

You need to call the static method check_mandatory_attr_on_view of class cl_wd_dynamic_tool. This would then automatically verify if all the mandatory fields have been filled or not. It would then populate the error messages into an internal table and display them in the view. Also the mandatory fields which haven't been filled would be highlighted with a red border. You need to put the below coding into the action up on which you want to trigger the data chesks.

data: lt_msg TYPE cl_wd_dynamic_tool=>t_check_result_message_tab,

lo_view_controller TYPE REF TO if_wd_view_controller,

lo_message_manager type ref to if_wd_message_manager.

lo_view_controller ?= wd_this->wd_get_api( ).

lo_message_manager = lo_view_controller->get_message_manager( ).

cl_wd_dynamic_tool=>check_mandatory_attr_on_view(

EXPORTING

view_controller = lo_view_controller

display_messages = abap_true

IMPORTING

messages = lt_msg ).

Ram

Answers (3)

Answers (3)

uday_gubbala2
Active Contributor

Hi Stanley,

You need to call the static method check_mandatory_attr_on_view of class cl_wd_dynamic_tool. This would then automatically verify if all the mandatory fields have been filled or not. It would then populate the error messages into an internal table and display them in the view. Also the mandatory fields which haven't been filled would be highlighted with a red border. You need to put the below coding into the action up on which you want to trigger the data checks.

data: lt_msg TYPE cl_wd_dynamic_tool=>t_check_result_message_tab,
          lo_view_controller TYPE REF TO if_wd_view_controller,
          lo_message_manager type ref to if_wd_message_manager.
 
  lo_view_controller ?= wd_this->wd_get_api( ).
  lo_message_manager = lo_view_controller->get_message_manager( ).
 
  cl_wd_dynamic_tool=>check_mandatory_attr_on_view(
    EXPORTING
      view_controller = lo_view_controller
      display_messages = abap_true
    IMPORTING
      messages = lt_msg ).

Regards,

Uday

Former Member
0 Kudos

Hi,

You actually have to check that whether the InputField is null in the onActionSubmit() method of your view,

Ex: If you want the Name InputField to be mandatory, just add the following code in the onActionSubmit() method of your view,

onActionSubmit()

{

String name = wdContext.currentEmployeeElement().getName();

//Check whether Name is not entered

if (name == null)

{

//Report an exception message

wdComponentAPI.getMessageManager().reportException(text_fill,true);

//text_fill can be any message of type String

}

}

pranav_nagpal2
Contributor
0 Kudos

hi Stanley,

as Uday had suggested you can use

cl_wd_dynamic_tool=>check_mandatory_attr_on_view(

Exporting

view_controller = lo_view_controller

DISPLAY_MESSAGES = ABAP_FALSE

Importing

messages = msg_tab ).

this method to check all the mandatory fields...........

Also to stop the furthur navigation after checking all the mandatory fields you have to write the below code as well.........

FIELD-SYMBOLS: <lv_fs> TYPE ANY.

DATA: lv_flag TYPE i.

loop at msg_tab ASSIGNING <lv_fs>.

if <lv_fs> is INITIAL.

exit.

ELSEIF <lv_fs> is NOT INITIAL.

lv_flag = 3.

endif.

endloop.

CHECK lv_flag ne 3.

regards,

Pranav