Professional Documents
Culture Documents
1. 2. 3. 4. 5. Attachments:32 Added by Rui Nogueira, last edited by Guest on Jun 05, 2008 (view change) Goal Pre-Requisites Step-by-Step Solution References and Related Topics Open Issues and Questions
1. Goal
Once you start developing with Web Dynpro you'll get excited about its functionality. Additionally it supports you a lot in quickly developing web-based user interfaces. Normally you start with one component and start adding more and more views to it. At a certain point you'll have so many views in a component that it starts getting difficult to add new functionality to your Web Dynpro application. At this point you start thinking if the Web Dynpro Components could help here. But normally you suppress this idea. Supported by the rule "Never touch a running system!" you go ahead until it really starts hurting you to maintain all these views in one component (see picture below).
Picture 1: Web Dynpro Explorer showing one component with many views
Picture 2: Diagram View of the default window This section wants to give you some hints on how to migrate from a "one-component-only" application to an application that uses components. Componentization itself is not very easy to understand. So please don't understand this step-by-step solution as the only way to do it or as a comprehensive description. Nevertheless it should help you over the first hurdles. Note: The example shown here is based on a simple Web Dynpro project. This is suitable for little developments. If you are working in a team you should use the NWDI and the component concept that consists of products, software components and development components. Have a look at the following link for more details: http://help.sap.com/saphelp_nw04/helpdata/de/01/9c4940d1ba6913e10000000a1550b0/frameset.htm[\] Furthermore you should keep the following issues in mind when starting Web Dynpro development:
Dont do any business logic in view controllers. All business logic should be done in the model. If you have UI logic try to implement it in custom or component controllers, if possible in a separate DC. From there it can be reused.
Use a middleware Web Dynpro DC for the communication with your backend systems. So the UI developer does not have to know anything about connecting backend systems, you can unify error handling, logging and other crosscutting issues. Furthermore in the Java world it is a common way to separate responsibilities into several development entities.
Always realize your first Web Dynpro project together with an experienced Web Dynpro consultant. The consultant can show you best practices and prevents you from failing into a trap.
2. Pre-Requisites
SAP NetWeaver: 7.0 (formerly 2004s). User: Already familiar with Web Dynpro Views and the context-concept. Project: A Web Dynpro project with multiple views. These views might have 1:n relationships in the context they display (e.g. a table with a list of projects and below a table with a list of comments that are related to a project).
3. Step-by-Step Solution
If you want to switch to a component based architecture you'll have to solve these major issues: 1. 2. 3. 4. Wisely bundle the views you have to components Share the same context within multiple components Bundle all you components again into one application Be able to update one component depending on an event triggered by another component
CompPrjList (the component handling the project list and all related views to add/edit/delete a project) CompPrjDetails (the component handling the project's details and all related views to edit) CompComments (handling the project's comments and all related views to add/edit/delete a comment) To create them you need to simply copy your initial component and paste it into your project. As we need to create three additional components we do it exactly three times. These are the steps you need to go through: TBD
CompRoot To create it copy again your initial component and paste it as a new component into your project.
Picture 2: Set the lifecycle to "manual" In this use-case we need apply this change for the following components:
CompRoot CompPrjList CompPrjDetails CompComments Please be aware that the data component is part of the "Used Web Dynpro Components" of these four components. If this isn't the case please refer to section 3.2.1 that describes how you do it.
Picture 3: Open the component controllers' implementation tab and insert the code The first code line creates an instance of the data component. The second line assigns the the data components' reference to a variable. This variable can now be used to tell the other components where they find the data component that they use.
CompPrjList CompPrjDetails CompComments The easiest way to provide the reference is to create a dedicated method in all of the components' interface controllers. From each components' interface controller we need to forward the reference to the components controller. Once the reference has reached the components' controller we use the "referencing" mode to provide the controller with the instance for the data component. The picture below explains the principle how this is handled.
Picture 1: Principle of "referencing mode" So what needs to be done? Let's go on step-by-step and use the component CompComments as example:
We need to connect the interface controller with the component controller We create a method called "referenceDataComp" in the interface controller This method will forward the reference it'll get from the root component to the component controller of CompComments We create a method called "referenceDataComp" in the component controller This method will be used to connect to the data component through the "referencing mode"
Picture 2: Open the component "CompComments" and click on "create a data link"
Picture 3: Connect the interface controller with the component controller (no additional context elements necessary)
Picture 10: The newly created method for the component interface controller
Picture 11: Add the code line in the newly created method "referenceDataComp" Now you have properly setup the components' interface controller. Next you need to double-click to the component controller and do exactly the same steps as shown from picture 5 to picture 10.
Picture 12: To the same for the component controller now (see picture 5 to picture 10) At then end you should have a method in the components' controller as shown below
Picture 13: The newly created method referenceDataComp for the components' controller
Picture 14: Switch to the implementation tab, search for the newly created method and enter the code shown above We accomplished our tasks for the component CompComments. We need to follow the same steps for the components CompPrjList and CompPrjDetails now. Simply follow the instructions from picture 2 to picture 14. Once all component interfaces are available we can now open our root component again and provide the CompData-reference to all other components. Beforehand we firstly have to "tell" our root component where to get the other components' referenceCompData-methods. So we will:
Open the root component again Provide the root component with the other components' referenceCompData method Provide the reference to the data component to the other components through their referenceCompData method
Picture 15: Open the root component, click on "properties" tab and click on "Add"
Picture 16: Select all components and their interfaces and click on "OK"
Picture 17: That's how it should look like after adding the components
Picture 18: Switch to the "Implementation" tab and add the code as shown in picture The three additional code lines in the root components' component controller call the other components' interface controller and provide them with the reference to the data component.
From this point on every component is using the same instance of the data component.
Create a new method "getData" in the data components' interface controller Forward the request to the components' controller Request the data in the component controller Use the data component method "getData" in the root components component controller method "wdDoInit"
Picture 5: Once created it should be visible as new method in the component interface controller of CompData
Picture 6: Switch to the "Implementation" tab and add the request to fill the context (in this case the list of projects) At this point we have now created a new method that can be called by the root components' controller. Therefore we just add it to our code in "wdDoInit" of the root components' controller.
*Picture 7: * That's it. Now your application should be working properly. Of course you need to adapt to the application that you have. But these are the basic things you need to do.