cancel
Showing results for 
Search instead for 
Did you mean: 

Check mandatory attributes of other view..

Former Member
0 Kudos

Hi ,

  

    I have a view ( view 1 ) which contains some input fields and a view container ( contains view 2 embedded ). Now I have a submit button in view 1.

in the action of this button I am checking required fields in view 1 by using following method :-

   DATA: LIF_VIEW_CONTROLLER TYPE REF TO IF_WD_VIEW_CONTROLLER.

  LIF_VIEW_CONTROLLER = WD_THIS->WD_GET_API( ).  ( " view controller of view 1 )

    CALL METHOD CL_WD_DYNAMIC_TOOL=>CHECK_MANDATORY_ATTR_ON_VIEW
    EXPORTING
      VIEW_CONTROLLER  = LIF_VIEW_CONTROLLER
      DISPLAY_MESSAGES = ABAP_TRUE
    IMPORTING
      MESSAGES         = LT_MESSAGES.

But this method check only required fields of the current view ( in my case view 1 ).

There are some required fields in view 2 and I also want to check them at the time of submit.

To achieve this I have created a node with a attribute ( type ref to IF_WD_VIEW_CONTROLLER ) . In the WDDOINIT method of the view 2 i am passing the

view controller of the second view to this node.

   LIF_VIEW_CONTROLLER = WD_THIS->WD_GET_API( ).    ( " view controller of view 2 )
  

" set attribute of the node

      lo_el_view_ref->set_attribute(
    name `VIEW_CONTROLLER`
    VALUE = lv_view_controller ).

now I am fetching the view controller ref of the view 2 in view 1 and checking the mandatory attribute of both the view in the submit of the first.

The above approach is working fine.

Please have a look on this solution also suggest me in case any issue or if any other approach is possible.

Regards,

Monishankar

Accepted Solutions (1)

Accepted Solutions (1)

amy_king
Active Contributor
0 Kudos

Hi Monishankar,

That is a nice, creative solution. Another approach could be, if you have defined your context nodes in the componentcontroller and copied/mapped them from the componentcontroller to each view as needed, your view could delegate the work of checking mandatory fields to the componentcontroller. In this case, you would use method cl_wd_dynamic_tool=>check_mandatory_attributes and pass into it the names of attributes you want to check.

data ls_attr type cl_wd_dynamic_tool=>t_check_mandattr_struct.
data lt_attributes type cl_wd_dynamic_tool=>t_check_mandattr_tab.
data lv_error type wdy_boolean.

ls_attr-node_path      = wd_this->wdctx_mynode.
ls_attr-element_index  = -1. " lead selection  
ls_attr-attribute_name = 'ATTRIBUTE_1'.
append ls_attr to lt_attributes.
ls_attr-attribute_name = 'ATTRIBUTE_2'.
append ls_attr to lt_attributes.

lv_error = cl_wd_dynamic_tool=>check_mandatory_attributes(
    attribute_list   = lt_attributes
    display_messages = abap_false
    context_root     = wd_context
).

Cheers,

Amy

Former Member
0 Kudos

Thanks Amy !

Answers (0)