Entering content frame

Procedure documentation Code Example for Programming Portal Eventing Locate the document in its SAP Library structure

Use

Example Description

The user can enter an arbitrary string in an input field. If the user presses the pushbutton Click here in the sender view, the input string will be displayed in a TextView UI element of the listener application.

This graphic is explained in the accompanying text

Prerequisites

You have built two Web Dynpro applications. How to built Web Dynpro applications is described in Creating a Simple Web Dynpro Application. In each application you have created a Web Component with a view that uses the portal eventing.

You can find the detailed procedure describing how to insert UI elements into a view in Creating a Simple Web Dynpro Application.

Further information about the integration of a Web Dynpro application into the SAP Enterprise Portal can you find under Running a Web Dynpro Application in SAP Enterprise Portal.

Procedure

Creating the Web Dynpro applications

...

      1.      Create the Web Dypro project. Call it _webdynpro_example_portal_eventing.

      2.      Create two Web Dynpro components. Call them:

                        a.     EventSenderComponent

                        b.     EventListenerComponent

      3.      Create two Web Dynpro applications. Call them:

                        a.     EventSenderApplication

                        b.     EventListenerApplication

Creating the necessary views:

Create the layout of the EventSenderView in the EventSenderComponent as follows:

This graphic is explained in the accompanying text

Create the context structure of the EventingSender View:

This graphic is explained in the accompanying text

The context value attribute Name must be of type String.

Create an action “Show”

Define the data binding of corresponding UI element properties:

The appropriate properties of the UI elements must be bound to the context that contains and displays the data.

      4.      Define a text, for instance, “Enter a text:” for the label UI element (ID: NameLabel) using the property text.

      5.      Bind the property value of the input field (ID: NameInputField) to the context attribute Name.

      6.      Bind onAction of the button (ID:ShowButton) to the corresponding action Show.

Implementation of the view controller

      7.      If you create an action declaratively within the SAP NetWeaver Developer Studio, the Web Dynpro framework automatically generates an onAction method in the controller’s implementation. The generated method enables you to write code to fetch the input string and to fire the portal event. The fire method of WDPortalEventing passes the data and the name of the event that should be handled by the second application as parameters. The following code shows the implementation of onActionShow method:

 

public void onActionShow(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

  {

    //@@begin onActionShow(ServerEvent)

   String name = wdContext.currentContextElement().getName();

    WDPortalEventing.fire("urn:com.sap.tc.webdynpro.example.portaleventing",

                       "Show",

                       name);

    //@@end

  }

 

Create the layout of the EventListenerView in the EventListenerComponent as follows:

This graphic is explained in the accompanying text

Create the context structure of the EventingListenerView:

This graphic is explained in the accompanying text

The context attribute Name must be of type String.

Create an action, for example, ReactPortalEventing which should be mapped to the portal event.

      8.      Create an action ReactPortalEventing.

      9.      Add the parameter dataObject. It should have the type java.lang.String.

Define the data binding of the corresponding UI element properties:

The corresponding properties of the UI elements must be bound to the context that contains and displays the data.

10.      Define a text for the NameLabel for example, The entry is displayed in a TextView UI element:

   11.      Bind the property text of the TextView UI element (ID: TextViewShow) to the context attribute Name.

Implementation of the view’s controller

   12.      You have to subscribe to the event within the wdDoInit method. You have to define the namespaceof the event and the name of the event, for example Show. The third parameter is the Web Dynpro action, which should be mapped to the portal event.

   13.      You have to implement the action (ReactPortalEventing) that passes the dataObjectand fills the context with data. The following code shows the implementation of the wdDoInit and the reactPortalEventing methods:

 

public void wdDoInit()

  {

    //@@begin wdDoInit()

    WDPortalEventing.subscribe("urn:com.sap.tc.webdynpro.example.portaleventing", "Show",

    wdThis.wdGetReactPortalEventingAction() );

    //@@end

  }

  

 

public void onActionReactPortalEventing(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent, java.lang.String dataObject )

  {

    //@@begin onActionReactPortalEventing(ServerEvent)

    wdContext.currentContextElement().setName(dataObject);

    //@@end

  }

Deploying the Web Dynpro Application

Before you can call the Web Dynpro application, you have to built the Web Dynpro project and deploy the application on the J2EE Engine.

Simple Testing of the Portal Eventing and Calling the Web Application

   14.      Create two iViews in the newly-created example folder as described in Running a Web Dynpro Application in SAP Enterprise Portal.

   15.      Create a page and add the two iViews to the newly-created page.
To preview the Web Dynpro applications, choose the button Preview in the Portal Content Studio.

   16.      Enter your input and choose button Click here.

Result

A page preview will demonstrate portal eventing.

  

  

Leaving content frame