zoukankan      html  css  js  c++  java
  • WDA学习(15):Self_Defined Function for ALV

    2.7 Self_Defined Function for ALV

           本实例展示创建自定义toolbar的function功能按钮,输入框。

    1.创建Web Dynpro Component,声明使用ALV组件

     

     2.在主键控制器创建上下文Function_Elements

     

     将主主键控制器的Function_elments节点和ALV接口控制器的Function_Elements节点绑定

     

     3.修改MAIN视图组件

    Properties页签,声明使用ALV组件及接口控制器

     

     Layout页签,选择ROOTUIELEMENTCONTAINER,右键创建ViewContainerUIElement,作为容器显示ALV;

     

     Context页签

    创建NODE_SFLIGHT节点,保存sflight表查询到数据;

    创建映射Function_Elements,保存自定义function输入框输入carrid值;

     

     

     Methods页签

    实现WDDOINIT方法,查询数据,设置自定义Toolbar function;

    代码实例:

    method WDDOINIT .
      "上下文节点绑定内表数据
      DATA:lo_node TYPE REF TO if_wd_context_node.
      DATA:lt_sflight TYPE wd_this->Elements_node_sflight.
    
      "查询数据
      SELECT * INTO CORRESPONDING FIELDS OF TABLE lt_sflight FROM sflight.
    
      "获取节点
      lo_node = wd_context->get_child_node( 'NODE_SFLIGHT' ).
      "内表数据绑定到上下文节点
      lo_node->bind_table( lt_sflight ).
    
      "实例化ALV组件
      DATA:lo_cmp_usage type ref to if_wd_component_usage.
      lo_cmp_usage =   wd_this->wd_cpuse_alv( ).
      if lo_cmp_usage->has_active_component( ) is initial.
        lo_cmp_usage->create_component( ).
      endif.
    
      "设置上下文节点数据绑定到ALV
      DATA:lo_INTERFACECONTROLLER TYPE REF TO IWCI_SALV_WD_TABLE .
      lo_INTERFACECONTROLLER = wd_this->wd_cpifc_alv( ).
      lo_interfacecontroller->set_data(
    *   only_if_new_descr =             " wdy_boolean
        r_node_data = lo_node           " ref to if_wd_context_node
    
      ).
    
      "获取config model(get_model方法必须在set_data方法后)
      DATA lv_value TYPE ref to cl_salv_wd_config_table.
      lv_value = lo_interfacecontroller->get_model( ).
    
      "设置header
      DATA:lo_table_settings TYPE REF TO if_salv_wd_table_settings.
      DATA:lo_header TYPE REF TO cl_salv_wd_header.
    
      "获取表格设置类对象
      "通过get_table_settings方法,获取if_savl_wd_table_settings对象
      "lo_table_settings = lo_config->IF_SALV_WD_VIEW_SETTINGS~GET_TABLE_SETTINGS( ).
      "可以强转cl_salv_wd_config_table类对象,得到if_savl_wd_table_settings对象
      lo_table_settings ?= lv_value.
    
      "设置alv table头
      lo_header = lo_table_settings->GET_HEADER( ).
      lo_header->SET_TEXT( 'flight info' ).
    
      "创建功能按钮
      DATA:lo_button TYPE REF TO cl_salv_wd_fe_button.
      "输入框
      DATA:lo_input TYPE REF TO cl_salv_wd_fe_input_field.
      "分割线
      DATA:lo_separator TYPE REF TO cl_salv_wd_fe_separator.
    
      "实例化对象,这里VALUE_ELEMENTNAME就是ALV接口控制器中绑定的FUNCTION_ELEMENTS
    
      CREATE OBJECT lo_input
        EXPORTING
          VALUE_ELEMENTNAME = 'CARRID'.
    
      CREATE OBJECT lo_button.
      CREATE OBJECT lo_separator.
    
      "设置button按钮属性
      lo_button->SET_TEXT( 'searchs' ).
      lo_button->SET_IMAGE_SOURCE( 'ICON_FLIGHT' ).
      lo_button->SET_IMAGE_FIRST( abap_true ).
      lo_button->SET_TOOLTIP( 'search flight' ).
    
      "设置input框属性
      lo_input->SET_LABEL_TEXT( 'Flight ID' ).
    
     
    
      DATA:lo_function_input TYPE REF TO cl_salv_wd_function.
      DATA:lo_function_sep TYPE REF TO cl_salv_wd_function.
      DATA:lo_function_button TYPE REF TO cl_salv_wd_function.
    
      "创建function对象,input框
      lo_function_input = lv_value->IF_SALV_WD_FUNCTION_SETTINGS~CREATE_FUNCTION( id = 'INPUT' ).
    
      lo_function_input->SET_EDITOR( lo_input ).
    
      "创建分割符
      lo_function_sep = lv_value->IF_SALV_WD_FUNCTION_SETTINGS~CREATE_FUNCTION( id = 'SEP' ).
      lo_function_sep->SET_EDITOR( lo_separator ).
    
      "创建button
      lo_function_button = lv_value->IF_SALV_WD_FUNCTION_SETTINGS~CREATE_FUNCTION( id = 'SEARCH' ).
    
      lo_function_button->SET_EDITOR( lo_button ).
    endmethod.
    View Code

    创建ONALVFUNCTION方法,实现ALV的on_function事件回调方法

     

     代码实例:

    method ONALVFUNCTION .
      CASE r_param->id.
        WHEN 'SEARCH'.
          "调用搜索功能
          DATA:lo_node TYPE REF TO if_wd_context_node.
          DATA:lo_element TYPE REF TO if_wd_context_element.
          DATA:lt_sflight TYPE wd_this->Elements_node_sflight.
          DATA:lv_carrid TYPE sflight-carrid.
          DATA:ls_where TYPE C LENGTH 72.
          DATA:lt_where LIKE TABLE OF ls_where.
    
          "获取Function_Elements节点
          lo_node = wd_context->get_child_node( 'FUNCTION_ELEMENTS' ).
          lo_node->GET_ATTRIBUTE( EXPORTING name = 'CARRID' IMPORTING value = lv_carrid ).
    
          IF lv_carrid IS NOT INITIAL.
            ls_where = 'CARRID = ' && '''' && lv_carrid && ''''.
            APPEND ls_where TO lt_where.
            "查询数据
            SELECT * INTO CORRESPONDING FIELDS OF TABLE lt_sflight FROM sflight WHERE (lt_where).
            "获取节点
            lo_node = wd_context->get_child_node( 'NODE_SFLIGHT' ).
            "内表数据绑定到上下文节点
            lo_node->bind_table( lt_sflight ).
    
          ENDIF.
        WHEN OTHERS.
      ENDCASE.
    
    endmethod.
    View Code

    4.设置Window窗口组件

     

     5.创建Web Dynpro Application,运行测试

     

  • 相关阅读:
    网页特殊符号HTML代码大全
    TypeScript在react项目中的实践
    koa源码阅读[3]-koa-send与它的衍生(static)
    微任务、宏任务与Event-Loop
    koa源码阅读[2]-koa-router
    koa源码阅读[1]-koa与koa-compose
    koa源码阅读[0]
    TypeScript在node项目中的实践
    我的博客即将入驻“云栖社区”,诚邀技术同仁一同入驻。
    Javascript装饰器的妙用
  • 原文地址:https://www.cnblogs.com/tangToms/p/12900642.html
Copyright © 2011-2022 走看看