web dynpro message(备忘用)

 1     DATA lo_api_controller     TYPE REF TO if_wd_controller.
 2     DATA lo_message_manager    TYPE REF TO if_wd_message_manager.
 3 
 4     lo_api_controller ?= wd_this->wd_get_api( ).
 5     CALL METHOD lo_api_controller->get_message_manager
 6       RECEIVING
 7         message_manager = lo_message_manager.
 8 
 9     DATA lv_ebeln TYPE ebeln.
10     lv_ebeln = WD_COMP_CONTROLLER->cust_get_if( ).
11 
12 
13     IF lv_ebeln is INITIAL.
14 
15 * report message
16 
17       CALL METHOD lo_message_manager->REPORT_ERROR_MESSAGE
18         EXPORTING
19           message_text              = '请输入必要的字段!'
20           show_as_popup             = 'X'
21           cancel_navigation         = 'X'
22 *        enable_message_navigation = 'X'
23           .
24     ENDIF.

 

SUCCESS:

复制代码
method ONACTIONSUCCESS .
* get message manager
data lo_api_controller     type ref to if_wd_controller.
data lo_message_manager    type ref to if_wd_message_manager.
data: l_text type string.
l_text = wd_Assist->get_text( wd_assist->text1 ).

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_SUCCESS
  EXPORTING
    MESSAGE_TEXT              = l_text   .


endmethod.
复制代码

WARNING:

复制代码
method ONACTIONWARNING .
    data: l_text type string.

*   get message manager
  l_text = wd_assist->get_text( wd_assist->text1 ).
  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_WARNING
    EXPORTING
      MESSAGE_TEXT              =  l_text.
endmethod.
复制代码

ERROR:

复制代码
method ONACTIONERROR .
    data: l_text type string.

*   get message manager
  l_text = wd_assist->get_text( wd_assist->text1 ).
  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              = l_text
endmethod.
复制代码

ERROR关联元素中的数据

复制代码
method ONACTIONERROR_PAR .
  data: l_text type string,
      l_value type I,
      l_params type wdr_name_value_list,
      l_param type wdr_name_value.

  wd_context->get_attribute( exporting name = 'INTEGER' importing value = l_value ).

  l_text = wd_Assist->get_text( wd_Assist->text2 ).

  l_param-name = 'P1'.
  l_param-value = l_value.
  append l_param to l_params.

* 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              =  l_text
    PARAMS                    =  l_params.
endmethod.
复制代码

ERROR关联元素

复制代码
method ONACTIONERROR_LT_1000 .
  data: l_value type I,
        l_text type string.
  DATA lo_el_context TYPE REF TO if_wd_context_element.
  DATA ls_context TYPE wd_this->Element_context.


wd_context->get_attribute( exporting name = 'INTEGER' importing value = l_value ).
IF l_value < 1000.
  lo_el_context = wd_context->get_element( ).
   l_text = wd_Assist->get_text( wd_Assist->text1 ).
*    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_ATTRIBUTE_ERROR_MESSAGE
     EXPORTING
       MESSAGE_TEXT              = l_text
       ELEMENT                   = lo_el_context
       ATTRIBUTE_NAME            = 'INTEGER'
       .



ENDIF.
endmethod.
复制代码

异常消息:

EXCEPTION

 

复制代码
method ONACTIONERROR_EXCEPTION .
    data: l_exc type ref to cx_wdr_demo_messages.
  create object l_exc.
*   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_EXCEPTION
    EXPORTING
      MESSAGE_OBJECT            = l_exc
endmethod.
复制代码

 

异常关联元素

复制代码
method ONACTIONATTR_WARN_EXCEPTION .
    data: l_exc     type ref to cx_wdr_demo_messages,
        l_value   type I,
        l_element type ref to if_wd_context_element.
      wd_context->get_attribute( exporting name = 'INTEGER' importing value = l_value ).
  TRY.
     wd_assist->CHECK_VALUE_LT_1000( l_value ).

  CATCH cx_wdr_demo_messages into l_exc.
    l_element = wd_context->get_element( ).
*     get message manager
* 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_ATTRIBUTE_EXCEPTION
  EXPORTING
    MESSAGE_OBJECT            = l_exc
    ELEMENT                   = l_element
    ATTRIBUTE_NAME            =  'INTEGER'
*    MSG_USER_DATA             =
    MESSAGE_TYPE             = lo_message_manager->CO_TYPE_WARNING
  ENDTRY.
endmethod.
复制代码

 

posted @ 2015-10-08 16:58  明大叔  阅读(755)  评论(0编辑  收藏  举报