Professional Documents
Culture Documents
How To Navigate Inside Web Dynpro Component Interface Views
How To Navigate Inside Web Dynpro Component Interface Views
Applies to:
Web Dynpro for Java UI Development, SAP NetWeaver 2004, SAP NetWeaver 2004s
Summary
This article was inspired by the repeated question on how to navigate to a certain view inside a Web Dynpro component (cross-component navigation). As soon as another component interface view wants to navigate to a specific flavor of the target component interface view, we must apply some tricks to fulfill this task. Specific flavor of a component interface view means that we want to display another view other than the defined default view within the target component. This article describes a solution to navigate inside Web Dynpro component interface views, based on serverside-eventing and an additional navigation dispatcher view. It also demonstrates how to transfer parameter values with outbound plugs, inbound plug event handlers, events, and methods across component and controller borders. Created on: 9 May 2006
Author Bio
After his studies in mathematics, physics and computer science Bertram Ganz finished his teacher training at a German grammar school stressing technical sciences. He has been a member of the Web Dynpro Java Runtime development team (SAP NetWeaver ESI Foundation UI) since 2002. The main focus of his work is on knowledge transfer, rollout, and documentation. Bertram regularly publishes articles on Web Dynpro in the context of the SAP NetWeaver Application Server. He also runs several Web Dynpro trainings and is the coauthor of the SAP Press Book, Java Programming with the SAP Web Application Server.
2006 SAP AG
Table of Contents
Summary.......................................................................................................................................... 1 Author Bio ........................................................................................................................................ 1 Table of Contents ............................................................................................................................ 2 Table of Contents ............................................................................................................................ 2 Concept Web Dynpro Navigation Basics...................................................................................... 3 Scenario Navigating from and to Component Interface Views..................................................... 3 Example ....................................................................................................................................... 3 Problem How to Navigate from Outside to Inside a Component Interface View.......................... 4 Solution - Navigation Dispatcher View and Server-side Eventing................................................... 5 Declaration and Implementation Tasks ........................................................................................... 6 Step 1 - Create New NavDispatcherView .................................................................................... 6 Step 2 - Add New ViewContainerUIElement................................................................................ 6 Step 3 - Define New Outbound Plugs within the NavDispatcherView ......................................... 6 Step 4 - Embed All Views within the ViewContainerUIElement................................................... 6 Step 5 - Define New Navigation Links ......................................................................................... 6 Step 6 - Define Event DispatchNavigation in the Component Controller .................................... 7 Step 7 - Define Method fireDispatchNavigation in the Component Controller............................. 7 Step 8 - Subscribe Event Handler in the NavDispatcherView Controller .................................... 8 Step 9 - Implement Inbound Plug Event Handler ........................................................................ 8 Step 11 - Fire Outbound Plugs within NavDispatcherView.......................................................... 8 Conclusion ....................................................................................................................................... 9 Outlook............................................................................................................................................. 9 Related Content............................................................................................................................. 10 Sample Application .......................................................................................................................... 9 Prerequisites ................................................................................................................................ 9 Importing the Project .................................................................................................................... 9 Testing the Sample Application ................................................................................................. 10 Copyright........................................................................................................................................ 11
2006 SAP AG
2006 SAP AG
Figure 1 Navigation between Web Dynpro Component Interface Views To trigger the navigation from UICompB to UICompA the wdFirePlug-method must be fired within the controller code. This can be directly done within an action event handler of a view controller after having defined a controller usage relation to the component interface view controller. //@@begin javadoc:onActionNavigateToUICompA(ServerEvent) /** Declared validating event handler. */ //@@end public void onActionNavigateToUICompA( com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent) { //@@begin onActionNavigateToUICompA(ServerEvent) wdThis.wdGetUICompBInterfaceViewController() .wdFireCrossCompNavOut(); //@@end }
2006 SAP AG
Figure 2 How to navigate from outside to inside a component interface view The first and most simple step to solve this issue is to specify a new navigation plug parameter named targetView which passes an Id value for the requested target view within UICompA. The coding for firing the outbound plug within the navigation source component UICompB then looks like this: public void onActionNavigateToUICompA( com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent, int targetView ) { //@@begin onActionNavigateToUICompA(ServerEvent) wdThis.wdGetUICompBInterfaceViewController() .wdFirePlugCrossCompNavOut(targetView); //@@end } With this Id the target component UICompA can then dispatch to the right view. But how does this navigation dispatching inside the target component work? To dispatch the navigation from component interface view to a view inside the same component we must fire an additional outbound plug. But component interface views do not have special inner outbound plugs which can point to a view inbound plug inside the same component.
2006 SAP AG
2006 SAP AG
How to Navigate Inside Web Dynpro Component Interface Views Last but not least we must solve the following problem: how can we fire the NavDispatcherView's outbound plug from within the inbound plug event handler of UICompA's component interface view controller? As the NavDispatcherView controller cannot be used by or does not expose a IPublic-API to the component interface view controller we have to apply another mechanism for interacting between Web Dynpro controllers: server-side eventing. Figure 4 illustrates the event-based mechanism to dispatch navigation from within the component interface controller via the NavDispatcherView:
Figure 4 How to navigate from outside to inside a component interface view 1. First we fire the component controller event DispatchNavigation within the inbound plug eventhandler of the component interface view controller. This is done by calling the public method fireDispatchNavigationEvent(int targetView) within the IPublic-API of the component controller. 2. This method then fires the DispatchNavigation event itself: wdThis.wdFireEventDispatchNavigation(targetView). Notice that this method is not exposed within the IPublic-API of the component controller so that an additional "helper" method fireDisparchNavigationEvent() must be declared. 3. The NavDispatcherView subscribes its event handler onDispatchNavigation() to the DispatchNavigation event of the component controller. 4. It can then fire its own outbound plugs to navigate to the embedded views within the event handler onDispatchNavigation(). Step 6 - Define Event DispatchNavigation in the Component Controller Within the component controller we define a new serverside event named DispatchNavigation and declare the event parameter targetView of type integer for it. Step 7 - Define Method fireDispatchNavigation in the Component Controller Within the component controller we then declare a public method named fireDispatchNavigationEvent() and declare the method parameter targetView of type integer for it.
2006 SAP AG
How to Navigate Inside Web Dynpro Component Interface Views Step 8 - Subscribe Event Handler in the NavDispatcherView Controller Within the NavDispatcherView controller we declare the event handler onDispatchNavigation() and declare the event parameter targetView of type integer for it. This event handler is subscribed to the DispatchNavigation event of the component controller, after having declared the corresponding controller usage relation. Step 9 - Implement Inbound Plug Event Handler Within the component interface view controller of UICompA we fire the DispatcheNavigation event. This is done in the event handler of the component interface views inbound plug. To call the public method fireDispatchNavigationEvent() of the component controller the corresponding controller usage relation must be declared. //@@begin javadoc:onPlugDisplayViewIn(ServerEvent) /** Declared validating event handler. */ //@@end public void onPlugDisplayViewIn( com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent, int targetView ) { //@@begin onPlugDisplayViewIn(ServerEvent) wdThis.wdGetUICompAController().fireDispatchNavEvent(targetView); //@@end } Step 11 - Fire Outbound Plugs within NavDispatcherView Within the view controller method onDispatchNavigation() of the class NavDispatcherView.java we can then dispatch navigation plugs by firing the related outbound plug. //@@begin javadoc:onDispatchNavigation(ServerEvent) /** Declared validating event handler. */ //@@end public void onDispatchNavigation( com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent, int targetView ) { //@@begin onDispatchNavigation(ServerEvent) switch (targetView) { case 0 : wdThis.wdFirePlugViewOneOut(); break; case 1 : wdThis.wdFirePlugViewTwoOut(); break; case 2 :
2006 SAP AG
How to Navigate Inside Web Dynpro Component Interface Views wdThis.wdFirePlugViewThreeOut(); break; default: break; } //@@end }
Conclusion
As long as two views belong to the same component, the navigation from one view to the other can be directly defined with a single navigation link. In case these two views belong to separate components they cannot be directly linked with each other because they are hidden behind the component borders. This article described a practical solution for such a cross-component-navigation scenario by answering the following main question: How can we dispatch a component interface views inbound plug to an inbound plug of an inner target view? By introducing a special navigation dispatcher view inside the navigation target component we can create inner navigation links that are connected with the target views. Because the navigation dispatcher view must be always visible during the whole target component lifecycle we set its default-property to true and embedded all inner views within a ViewContainerUIElement. The navigation dispatcher views outbound plugs are fired from within interface view controller by firing an event and passing the id of the requested target view.
Outlook
You might ask why it is quite cumbersome in SAP NetWeaver 04 and 04s to navigate across Web Dynpro component borders. The answer is: there is no simpler solution because we cannot define inner outbound plugs within component interface views. To dispatch navigation we have to fire outbound plugs which can only be defined on view but not on interface view level. As a consequence of this issue the Web Dynpro component architecture will be enhanced within the next major SAP NetWeaver release so that navigation plugs can also be defined on the window level (window plugs). The component interface view controller will then be implemented by the new window controller so that the navigation dispatching mechanism described in this article can be managed by the window controller directly. A special navigation dispatcher view is then no longer needed because the window itself can dispatch navigation requests. Based on the new window plug concept, all cross-component-navigation scenarios can be implemented more easily within the next major SAP NetWeaver release.
Sample Application
This article is based on a Web Dynpro sample application, which is available for download on the SAP Developer Network (SDN) under Web Dynpro Sample Applications and Tutorials Cross-Component Navigation. Prerequisites The sample application is based on a SAP NetWeaver 04 Stack 14 installation. Importing the Project Read the instructions on how to import the Local Web Dynpro Sample DC into your developer workspace.
2006 SAP AG
How to Navigate Inside Web Dynpro Component Interface Views Testing the Sample Application The sample application starts with the component interface view of the UI Component A. Press the LinkToAction-UI-element to navigate to the other UI Component B. From there you can navigate back to a specific View within the target UI component A. Depending on the clicked LinkToAction-UI-element a specific value of the event parameter targetView is passed to the action event handler (see the previous section Problem How to Navigate from Outside to Inside a Component Interface View). Based on the described solution the corresponding view within the target UI Component A is displayed.
Related Content
1. Sample Application: Creating an Extended Web Dynpro Application 2. Sample Application: View Composition 3. Sample Application: Designing Component-Based Web Dynpro Applications
2006 SAP AG
10
Copyright
Copyright 2006 SAP AG. All rights reserved. No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG. The information contained herein may be changed without prior notice. Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors. Microsoft, Windows, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation. IBM, DB2, DB2 Universal Database, OS/2, Parallel Sysplex, MVS/ESA, AIX, S/390, AS/400, OS/390, OS/400, iSeries, pSeries, xSeries, zSeries, z/OS, AFP, Intelligent Miner, WebSphere, Netfinity, Tivoli, Informix, i5/OS, POWER, POWER5, OpenPower and PowerPC are trademarks or registered trademarks of IBM Corporation. Adobe, the Adobe logo, Acrobat, PostScript, and Reader are either trademarks or registered trademarks of Adobe Systems Incorporated in the United States and/or other countries. Oracle is a registered trademark of Oracle Corporation. UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group. Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registered trademarks of Citrix Systems, Inc. HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C, World Wide Web Consortium, Massachusetts Institute of Technology. Java is a registered trademark of Sun Microsystems, Inc. JavaScript is a registered trademark of Sun Microsystems, Inc., used under license for technology invented and implemented by Netscape. MaxDB is a trademark of MySQL AB, Sweden. SAP, R/3, mySAP, mySAP.com, xApps, xApp, SAP NetWeaver, and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and in several other countries all over the world. All other product and service names mentioned are the trademarks of their respective companies. Data contained in this document serves informational purposes only. National product specifications may vary. These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated companies ("SAP Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Group products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty. These materials are provided as is without a warranty of any kind, either express or implied, including but not limited to, the implied warranties of merchantability, fitness for a particular purpose, or non-infringement. SAP shall not be liable for damages of any kind including without limitation direct, special, indirect, or consequential damages that may result from the use of these materials. SAP does not warrant the accuracy or completeness of the information, text, graphics, links or other items contained within these materials. SAP has no control over the information that you may access through the use of hot links contained in these materials and does not endorse your use of third party web pages nor provide any warranty whatsoever relating to third party web pages. Any software coding and/or code lines/strings (Code) included in this documentation are only examples and are not intended to be used in a productive system environment. The Code is only intended better explain and visualize the syntax and phrasing rules of certain coding. SAP does not warrant the correctness and completeness of the Code given herein, and SAP shall not be liable for errors or damages caused by the usage of the Code, except if such damages were caused by SAP intentionally or grossly negligent.
2006 SAP AG
11