Generic Synchronization | Data containers | Wrapper functions
In this example we will use the Generic Sync API to read your own user information from the "backend" and display them in a JSP page.
The example is based on the event handling example from the Getting started section. It uses the same user interface but instead of displaying data about the Mobile Infrastructure installation the example displays your user information requested from the Web AS.
If above objects do not exist in your Web Application Server, you need to create the function module in the ABAP/4 Workbench (transaction SE80) and the mapping entry via the Data Browser (transaction SE16). |
The Generic Sync API provides methods to call function modules on a SAP system and process the response data. The servlet collects your user name, creates an outbound container and starts immediate synchronization. The inbound processor (that is registered by the servlet at initialization), retrieves the user information and stores it in a user information object. The servlet reads the user information from this object and stores it in a bean. The JSP is called by the servlet, retrieves the data from the bean and displays it in tabular form.
The MDK provides a template for this example. Click here to Download template.
The example uses following packages:
import com.sap.ip.me.api.conf.Configuration;
import com.sap.ip.me.api.runtime.jsp.AbstractMEHttpServlet;
import com.sap.ip.me.api.services.Log;
import com.sap.ip.me.api.sync.*
The coding of this example is very similar to the event example in the Getting Started section. The following parts are added:
Click here to learn more about Generic Synchronization.
Java |
Description |
GenericSyncExample.java | Implementation of the servlet. It registers the inbound processor, requests the user information from the Web AS and fills the bean. |
Constants.java | Interface with all necessary constants. |
InboundProcessing.java | Processes the inbound containers from Web AS and fills the UserInformation instance. |
UserInformation.java | Singleton that holds the user information delivered by the Web AS. |
TableViewBean.java | Implementation of the bean that is loaded by the servlet and read by the JSP. |
JSP |
Description |
welcome.jsp | Initial JSP displaying an input field and a submit button. |
tableView.jsp | JSP to display the user information. |
We create a class GenericSyncExample that extends the class AbstractMEHttpServlet and implements Constants. Constants is an interface in which we define all relevant variables for the application. All variables used in Constants are written in uppercase characters. So anytime you see an uppercase variable used in class GenericSyncExample you will find the definition in interface Constants.
The class GenericSyncExample extends AbstractMEHttpServlet which extends javax.servlet.http.HttpServlet itself. GenericSyncExample implements the methods:
Now comes the section were we check which event occurred. The event handled comes from the "Submit" button of the welcome page and causes following action:
event EVENT_NAME
Retrieve the string from the input field of the welcome page. The string is the user name. With the user name we generate a new head line and call getUserInfo(String userName) that triggers the inbound processor. The event, sent by the inbound processor when a inbound container arrives, is handled by InboundProcessing.java.
The next methods called are:
Now the JSP, defined in nextJSP, is called.
InboundProcessing.java
Implements the InboundProcessor. The method process is called whenever a inbound container arrives. The methodprocess is implemented in the way that every inbound container is stored in the UserInformation bean.
UserInformation.java
Is called be the InboundProcessing class. It contains the user information.
TableViewBean.java
The bean serves as data bag. It has a string, a string array and two variables
that define the length and width of the string array. All variables have get
and set methods.
You can also implement this example using only one bean. We have chosen this model, because the UserInformation.java contains the data according to the structure of the inbound processor. The TableViewBean.java represents the data in tabular form in preparation to be displayed by the tableView.jsp.
welcome.jsp
Displays a welcome message and allows to enter a user name. The JSP contains
a "Submit" button to send the page.
tableView.jsp
The JSP gets the bean from the session context with the useBean command.
It displays the the title and then uses the HTML grid (<td>, <tr>
...) to format the data in the bean. There are two for loops that display the
the rows (outer loop) and the columns (inner loop).