Skip to Content
author's profile photo Former Member
Former Member

Mandatory field check for each sub-view

Hi,

I have one main view and different sub-views which are embedded into the main view. The mandatory fields will be checked within WdDoBeforeAction of each sub-view with CL_WD_DYNAMIC_TOOL=>C_MANDATORY_ATTR_ON_VIEW. The Problem is that the user Need not to naviagte through each view so I can not be sure that each view is checked against it mandatory fields before the user presses the save button. So if the user presses the save button I must check all views and display the Errors. It would be nice if I can use the existing method. So is there an Option to instantiate alls sub-views if not already done and check the fields? Or is there a common way to handle this case?

Add a comment
10|10000 characters needed characters exceeded

Related questions

3 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Feb 19, 2014 at 08:04 AM

    Hi,

    thank you Kiran and Ramakrishnappa for your help.

    Because it does not seem to work with the view instance I have to go another way. The mandatory fields are binded to the required property of a context attribute. Then, I'm collecting all this requried attributes from my context node with a recursive method in an internal table and pass it to cl_wd_dynamic_tool=>check_mandatory_attributes(). It only checks whether there are any errors present and not where they are, but that's okay at the moment.


    Here are my two methods:

    - GET_REQUIRED_ATTRIBUTES: Importing IO_CONTEXT_NODE, Exporting ET_ATTRIBUTE_LIST

    - CHECK_REQUIRED_ATTRBUTES: Importing IO_CONTEXT_NODE, Returning RV_HAS_ERRORS

    method get_required_attributes.
    data:
    lo_context_node type ref to if_wd_context_node,
    lt_child_node type wdr_context_child_map,
    ls_child_node type wdr_context_child,
    lt_properties type wdr_context_properties_tab,
    ls_properties type wdr_context_properties,
    lt_attribute_list type t_check_mandattr_tab,
    ls_attribute_list type t_check_mandattr_struct.

    lt_properties = io_context_node->get_attribute_props_for_elem( ).

    loop at lt_properties into ls_properties where required = abap_true.
    ls_attribute_list-node_path = io_context_node->get_meta_path( withoutcontroller = abap_true ).
    ls_attribute_list-attribute_name = ls_properties-attribute_name.
    ls_attribute_list-element_index = 0.

    append ls_attribute_list to et_attribute_list.
    endloop.

    lt_child_node = io_context_node->get_child_nodes( ).

    loop at lt_child_node into ls_child_node.
    lo_context_node = ls_child_node-node.

    me->get_required_attributes(
    exporting
    io_context_node = lo_context_node
    importing
    et_attribute_list = lt_attribute_list
    ).

    append lines of lt_attribute_list to et_attribute_list.
    clear lt_attribute_list.
    endloop.
    endmethod.
    method check_required_attributes.
    data:
    lt_attribute_list type t_check_mandattr_tab,
    ls_attribute_list type t_check_mandattr_struct.

    me->get_required_attributes(
    exporting
    io_context_node = io_context_node
    importing
    et_attribute_list = lt_attribute_list
    ).

    rv_has_errors = cl_wd_dynamic_tool=>check_mandatory_attributes(
    attribute_list = lt_attribute_list
    display_messages = abap_false
    context_root = io_context_node
    ).
    endmethod.
    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Feb 18, 2014 at 08:19 AM

    Hi Christian,

    The method WDDOBEFOREACTION( ) calls for all views embedded in the current window before any action.

    Example:

    Let us say we have main view V_MAIN, V_SUB_VIEW1 & V_SUB_VIEW2

    Subviews are embedded in main view.

    Now, On any action on main view V_MAIN, wddobeforeaction( ) gets called and the validation logic of respective view goes here.

    But the action is not bound in all views except in the current view from where the action is triggered.

    I suggest, you set the action name in view to a global attribute in an assistance class or you can create it in component controller.

    Before any action, subviews will query the current action and based on the action, the respective logic for validation executes

    i.e.

    if SAVE action is triggerred from main view, set the global attribute wd_comp_controller->gv_action_name = lo_action->name

    Now, in subviews wddobeforeaction( ), you can access the action as below

    if wd_comp_controller->gv_action_name = 'SAVE'.

    " validation logic goes here

    endif.

    Hope this helps you.

    Regards,

    Rama

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Feb 18, 2014 at 06:32 AM

    Hi,

    Using IF_WD_RR_VIEW_USAGE Api you can get the embedding view usage reference.

    Sample Code:

    DATA:lr_view_controller type ref to IF_WD_VIEW_CONTROLLER,

    lr_main_view_usage type ref to IF_WD_RR_VIEW_USAGE.

    lr_vc_assignment type ref to IF_WD_RR_VIEW_CNT_ASSIGNMENT.

    lr_view_usage type ref to IF_WD_RR_VIEW_USAGE.

    lr_t_views type WDRR_VCA_OBJECTS.

    lr_s_view like line of lr_t_views.

    lr_view type ref to if_wd_rr_view.

    lr_view_controller = wd_this->wd_get_api( ).

    lr_main_view_usage = lr_view_controller->GET_VIEW_USAGE( ).

    lr_t_views = lr_main_view_usage->GET_VIEW_CNT_ASSIGNMENTS( ). "This will return all the View Container assignments.

    * Now loop over all the View containers and get the reference of embedding view.

    loop at lr_t_views into lr_s_view .

    lr_vc_assignment = lr_s_view-VIEW_CNT_ASSIGNMENT.

    lr_view_usage = lr_vc_assignment->GET_DEFAULT_VIEW_USAGE( ). " This will return view usage reference

    lr_view = lr_view_usage->get_view( ). " This will have the meta info of view

    * Do your processing..

    endloop.

    Hope this helps u,

    Regards,

    Kiran

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi,

      the user does not need to naviagte to each view and therefore I don't have all sub-view references.

      Where exactly your sub-views located? Aren't they embedded in the view container in main view? If they embed in main view automatically the DOINIT method will get called and you can get the view reference and set it to the component controller attributes.

      If I call each view with the Outbound-Plugs of my main view, are the sub-view instances created at this moment so I can use them for checking?

      Yes. When you navigate from one view to other for the first time the DOINIT method will be called and you can write the code to get the reference of view and set it to component controller attribute which you can access at later point.

      Regards,

      Kiran

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.