Show TOC Start of Content Area

Procedure documentation Registering Runtime Views Using Servlets  Locate the document in its SAP Library structure

Use

You can register the custom runtime views you have created using a servlet that is executed each time the service starts.

The following procedure describes how you can do this using the NetWeaver Developer Studio (NWDS).

Prerequisites

·        You have created a content component or a contextual panel component. For more information, see Creating Custom Runtime Views Using the GP API.

·        The versions of the Java Guided Procedures (GP) you use and your development track must match.

Procedure

...

       1.      Open the Development Infrastructure perspective and create a development component (DC) of type J2EE Enterprise Application.

       2.      Create a second DC of type J2EE Web Module.

       3.      Add the Web module to the enterprise application:

                            a.      Open the J2EE perspective and in the Project Explorer, select the enterprise application component from step 1.

                            b.      Navigate to the Modules folder of the application and from the context menu choose Add/Remove.

                            c.      From the Available J2EE Modules list, select the Web module component from step 2 and choose OK. 

       4.      In the Development Infrastructure perspective, select the Web module DC and add the following build-, deploy- and runtime dependencies:

¡        GP-CORE  caf/eu/gp/api (external)

¡        ENGFACADE   tc/bl/exception/lib (default)

¡        GP-CORE  caf/eu/gp/api/wd (ContentComponent)

       5.      Repeat the step above for the enterprise application DC.

       6.      To create a servlet, open the context menu of the Web module DC and choose New  Servlet…

                            a.      Provide a servlet name and package.

                            b.      Set the type to HTTP Servlet.

                            c.      Enable the init() and destroy() servlet methods.

       7.      In the new servlet class, replace the automatically-generated code with the one listed below:

Example

Example Servlet Code

package com.testcustomer;

 

import java.io.IOException;

import java.util.Enumeration;

import javax.servlet.ServletConfig;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

 

import com.sap.caf.eu.gp.rtview.api.GPRTViewFactory;

import com.sap.caf.eu.gp.rtview.api.IGPRTView;

import com.sap.caf.eu.gp.rtview.api.IGPRTViewManager;

import com.sap.caf.eu.gp.wdcomponent.api.GPWDComponentFactory;

import com.sap.caf.eu.gp.wdcomponent.api.IGPWDComponent;

import com.sap.caf.eu.gp.wdcomponent.api.IGPWDComponentManager;

import com.sap.localization.ResourceAccessor;

 

public class RegisterView extends HttpServlet {

   // a unique identifier for view

   final static String TYPE_NAME = "TestView";

   /**

    * init() is called once at the instantiation of the servlet

    * We register our new view here.

    */

   public void init(ServletConfig cfg) throws ServletException {

      super.init(cfg);

      boolean isRegistered = false;

  

      String viewId = TYPE_NAME;

      IGPRTViewManager vManager = GPRTViewFactory.getRTViewManager();

      try {

         // check if view is already registered:

         Enumeration rViews = vManager.getRTViews();

         while (rViews.hasMoreElements()){

            IGPRTView view = (IGPRTView)rViews.nextElement();

            if (view.getRTViewId().equals(viewId)){

               isRegistered = true;

               break;

            }

         }

         // if it is not registered

         if (isRegistered == false) {

            // instantiate the appropriate managers

            IGPWDComponentManager mgr = GPWDComponentFactory.getWDComponentManager();

            // create and register a Web Dynpro Component

            ResourceAccessor resourceAccessor = null;

            IGPWDComponent contentComponent = mgr.createWDComponent(

                     "MyOwnContentPane",

                     "com.sap.caf.eu.gp.runtime.view.CContentPane",

                    "sap.com/caf~eu~gp~runtime~view",

                    resourceAccessor,

                     "FrameTitle");

            // create and register a runtime view configuration

            IGPRTView viewConfiguration = vManager.createRTView(

                     viewId,

                     contentComponent,

                     resourceAccessor,

                     "PaneTitle",

                     "PaneDescription",

                     IGPRTView.MANDATORY_GROUP_PROCESS_STRUCTURE,

                     false);

            vManager.registerRTView(viewConfiguration); 

         }

      } catch (Exception e) {

         e.printStackTrace();         

      }

   }

   /**

    * destroy() is called when the instance of the servlet is destroyed

    * We unregister our new view here.

    */

   public void destroy() {

      super.destroy();

 

      String viewId = TYPE_NAME;

      IGPRTViewManager vManager = GPRTViewFactory.getRTViewManager();

      try {

         // unregister the runtime view

         vManager.unregisterRTView(viewId);

      } catch (Exception e) {

         e.printStackTrace();

      }    

   }

}

       8.      In the Project Explorer, expand the node of the Web module DC and select WebContent WEB-INF web.xml.

       9.      From the context menu, choose Open and open the Web Objects tab page:

                            a.      Expand the Servlets node and select the servlet you created previously.

                            b.      In the load on startup field, enter 1.

As a result, the servlet is executed every time the service starts.

   10.      Save, build and deploy your enterprise application.

 

More Information

Registering Web Dynpro Components and Runtime Views

End of Content Area