二维码

[教程] CUSTOM CONTROLLER AND DATA BINDING

Twilight发表于 2015-12-04 23:05Twilight 最后回复于 2015-12-04 23:05 [复制链接] 9761 0

Views lost its data as soon as user navigates away from the view. In order to solve this problem, Custom controllers are introduced.

We add same type of context nodes to the custom controllers and do the data binding between the custom controller context node and required view context node.

One UI component can have any number of custom controllers.

In our case, we will follow below logic for making data flow across context nodes of different views.
  • We will fetch data in the search event handler ( that we completed ).
  • We will fetch instance of custom controller and feed the data we fetched to its context node.
  • We will do the binding between result view context node and custom controller context node so that data will travel to the result view.

Let us create custom controller first.

Go to the UI component – component structure browser. Right click on CUSTOM CONTROLLER and choose option to CREATE.

Give the name that has prefix CuCo*.ex: CuCoSearch  CuCo stands for custom controller.
In the next step, give context node name as result and entity name as BTQRSrvCon, because we will bind this node to the result view context node.

Context node base entities should be same for binding.
Just complete the wizard by choosing continuebutton  and save the entries.  We have successfully created custom controller.
custom controller 1.jpg

Next we will bind the two context nodes. Go to the result view and  Right click on the result context node  and choose the option create binding.
custom controller 2.jpg

In the next pop up , choose the controller type as custom controller as we are binding the data to result view.
Choose CuCoSearch.do as view controller in the custom controller field and choose the result context node and press on right mark.  That’s it, we have done the binding.
custom controller 3.jpg

once above step is done, We can observer the binding here.
custom controller 4.jpg

It is saying the result context node of custom controller is bound to the result context node view RESULT.
Next we need to add small part of code to the search event handler to get the custom controller instance and feed the data that we have already fetched.

Go to the search event handler of search view and add the below code to it.
  1. METHOD eh_onsearch.

  2.   DATA:lr_selcriteria    TYPE REF TO cl_crm_bol_dquery_service,
  3.        lr_result         TYPE REF TO if_bol_bo_col.
  4.   DATA:lr_custcontroller TYPE REF TO zl_ztutcomp_cucosearch_impl.

  5.   lr_selcriteria ?= me->typed_context->search->collection_wrapper->get_current( ).
  6.   CHECK lr_selcriteria IS BOUND.
  7.   lr_result = lr_selcriteria->get_query_result( ).

  8.   lr_custcontroller ?= me->get_custom_controller('ZTUTCOMPONENT/CuCoSearch').
  9.   CHECK lr_custcontroller IS BOUND.
  10.   lr_custcontroller->typed_context->result->collection_wrapper->set_collection( lr_result ).

  11. ENDMETHOD.
复制代码

At line no 16, we used the method get_custom_controller to fetch the instance of custom controller by giving its name.

We are giving the returned data lr_result to the context node result of custom controller.

Test the application now just click on the search button. It will show some service contracts. Our search page is working now.
search result.jpg
回复

使用道具 举报

快速回帖

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

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