二维码

[教程] DISPLAYING NAVIGABLE MESSAGES

Twilight发表于 2016-02-05 22:58Twilight 最后回复于 2016-02-05 22:58 [复制链接] 556 0

NAVIGABLE MESSAGES :

In the previous chapter, we have created simple messages. At times, we have to execute certain actions to process the error message.
For ex:
By clicking on message, user has to navigate to some other screen or we need to execute certain code.
In this example, I will show how to navigate to another view by clicking on the message in the message bar.

Here I have created two views and made one navigation link from source view to target view and assigned both views to the window. I made source view as default view so that when we display the window, source view will be displayed first. Kindly see the below screen shot.
NAVIGABLE MESSAGES 1.jpg

We need to add one interface ‘IF_BSP_WD_MESSAGE_HANDLER’ to our view implementation class as a first step if it is not available already.
NAVIGABLE MESSAGES 2.jpg

After adding, activate the class.

Next, we need to subscribe our message to the global message service. I coded in the DO PREPARE OUTPUT method as below.
  1. METHOD do_prepare_output.

  2.   CALL METHOD super->do_prepare_output
  3.     EXPORTING
  4.       iv_first_time = abap_false.

  5.   DATA:lr_service TYPE REF TO cl_bsp_wd_message_service.

  6.   lr_service = me->view_manager->get_message_service( ).

  7.   TRY.
  8.       CALL METHOD lr_service->subscribe_message
  9.         EXPORTING
  10.           iv_message_class  = 'ZMSG_CLASS'
  11.           iv_message_number = '000'
  12.           iv_subscriber     = me
  13.           iv_activation     = abap_true.
  14.     CATCH cx_bsp_wd_dupl_mess_subscr .
  15.   ENDTRY.

  16.   lr_service->add_message( EXPORTING iv_msg_id = 'ZMSG_CLASS' iv_msg_number = '000' iv_msg_type = 'E' ).

  17. ENDMETHOD.
复制代码

First I am subscribing my message using the method subscribe message. Then I am adding the message to make visible on the web ui. Save and activate the method.

If you test application now, you can see that message will be displayed as hyperlink. Whenever user clicks on the hyper link, the method IF_BSP_WD_MESSAGE_HANDLER~HANDLE_MESSAGE will be triggered. We need to code in this method.

Go to the view implementation class and add the following code.
  1. METHOD if_bsp_wd_message_handler~handle_message.

  2.   "trigger the navigation.
  3.   me->view_manager->navigate( EXPORTING source_rep_view = me->rep_view
  4.                                         outbound_plug = 'tovaluenode' ).

  5. ENDMETHOD.
复制代码

I am simply triggering the navigation in this method.  I am giving the navigational link value to the outbound plug parameter.
Now testing the application.
NAVIGABLE MESSAGES 3.jpg

Click on the message. You will navigate the target view.
回复

使用道具 举报

快速回帖

本版积分规则
您需要登录后才可以回帖 登录 | 注册有礼

快速回复 返回顶部 返回列表