
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 SAP NetWeaver Developer Studio (NWDS).
| Example Servlet Code |
|---|
packagecom.testcustomer; importjava.io.IOException; importjava.util.Enumeration; importjavax.servlet.ServletConfig; importjavax.servlet.ServletException; importjavax.servlet.http.HttpServlet; importjavax.servlet.http.HttpServletRequest; importjavax.servlet.http.HttpServletResponse; importcom.sap.caf.eu.gp.rtview.api.GPRTViewFactory; importcom.sap.caf.eu.gp.rtview.api.IGPRTView; importcom.sap.caf.eu.gp.rtview.api.IGPRTViewManager; importcom.sap.caf.eu.gp.wdcomponent.api.GPWDComponentFactory; importcom.sap.caf.eu.gp.wdcomponent.api.IGPWDComponent; importcom.sap.caf.eu.gp.wdcomponent.api.IGPWDComponentManager; importcom.sap.localization.ResourceAccessor; publicclass 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(); } } } |
As a result, the servlet is executed every time the service starts.
More Information