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.
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.
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.
once above step is done, We can observer the binding here.
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.
METHOD eh_onsearch.
DATA:lr_selcriteria TYPE REF TO cl_crm_bol_dquery_service,
lr_result TYPE REF TO if_bol_bo_col.
DATA:lr_custcontroller TYPE REF TO zl_ztutcomp_cucosearch_impl.
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.
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.
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.
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.
once above step is done, We can observer the binding here.
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.
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.