!--a11y-->
Code Example for Programming Portal
Eventing 
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.

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.
...
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


The context value attribute Name must be of type String.
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.
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 }
|


The context attribute Name must be of type String.
8. Create an action ReactPortalEventing.
9. Add the parameter dataObject. It should have the type java.lang.String.
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.
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 } |
Before you can call the Web Dynpro application, you have to built the Web Dynpro project and deploy the application on the J2EE Engine.
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.
A page preview will demonstrate portal eventing.
