Link to Content's target Space :
Creation of dynamic Component Usages in CRM WebClient UI.
Arun Prakash Karuppanan
Created on: April 17 2010
Arun Prakash Karuppanan is a Software Programmer employed with Accenture, working on CRM implementations.
Table of Contents
The re-usability of BSP components in the form of a Component Usages is a good thing.We usually depend on static declarations in the runtime repository. However, in certain scenarios, this static declarations may be cumbersome. For example, when you want multiple reuse of the same component and do not know how many until at runtime. In these circumstances, we can dynamically create the component usages. Usually, the data is supplied by the calling component and this happens in the form of context node binding. Don't worry, we can do that as well.
Creating Dynamic Component Usages
Our scenario is multiple reuse of the same component. For binding purposes, we will need a existing context node which will serve as the model type, when creating the context nodes dynamically. The other thing is, all the component usages and context nodes are created dynamically and available only in memory. So, we will need a place where we can store these instances. If we follow a naming convention for the component usages and context nodes, it will make things easier as well. For example, CU_<Used_Component_name>_<Instance_Number> and similarly for context nodes. The storage place can be a table attribute in the component controller class.
Creating component usages is rather easy. Create a method in the component controller, that you can call when you need to create them.
Parameter iv_usage_name obviously takes in component usage name. We will not be using the second import parameter iv_reference_usage_name. Trying to use this results in a funny behaviour(the view controller gets shared and all of them behave in the same way in UI). However, since it is a mandatory parameter we will pass a blank here. iv_component_name is the component name.
Creating Context Nodes
Next, we will use an already available method in the component controller class to create context nodes at runtime. Note that you should have already created a context node that will serve as the model type. We will be creating several instances of this at run time.
Once you create the component usage and a context node for binding, you should store the instances in the table attribute in the component controller.
Context node binding
So now, we can create the component usage and the context node as well. How to do the data binding? Normally, this binding will be specified in the WD_USAGE_INITIALIZE method of the component controller. Note that the method used for binding there will look for statically created context nodes. Instead, we must make it look for the context node among the dynamically created instances. All the created context nodes will be available in the table m_models of the component controller. So, create a method in the component controller which will do the binding that suits our need.
Copy the method bind_context_nodes in the component controller and modify it as follows.
Note that you can get the component usage instance by using the method get_component_usage in the component controller. You need to pass the usage name.
Embedding in a view container
So, we have created the component usage and finished with the binding. Now, we must embed them in a view. For our scenario, creating view areas in a view set dynamically is preferable. We should construct a name for the view area following similar naming conventions used for the usages and context nodes. A dedicated view controller should be created for each view area. The code could be put in a suitable method in the view set's controller. The code could be something like
If you wish for a detailed working example, please access this document. I wrote this article, but since it was my first submission, messed up with the category and the name and thus it's been put in a place where it is nearly not as useful. The article actually focuses on CRM WebClient UI and the BSP component workbench(BSP_WD_CMPWB). I knew that the WD stands for WebDynpro. What I did not know was WebDynpro was a different platform altogether from the BSP Workbench!!! Yes, I was a frog in the well.
Dynamic Component Usage in CRM WebClient UI