SmartSync API Overview | Defining a SyncBo | Server Prerequisites for the Example
This example uses inventory data to demonstrate the following features of the SmartSync API:
The MDK provides a template for this example. Click here to download template for JSP or download template for AWT.
![]() |
The example needs the right Bapi wrappers to work correctly. Please refer to the document Server Prerequisites for the Example for details. |
Header Panel
The tableViewDefinition bean provides to methods to set the icon on the left hand side and the text on the right hand side. The icon can be used to navigate back to the MI home page.
Center Page
The center page is divided into the following sections:
- Command line
The tableViewDefinition bean provides methods to set the command line. The command line is made out of HTML buttons, of type submit, with a stylesheet class that removes the surrounding box. The submit button is necessary to have access to the form that contains the input fields in the table area. The commands supported are
- Add
To add a new entry- Set Filter/Reset Filter
With this command you can specify a starting pattern for products to be displayed. Like in the picture shown above, the filter is set to 10000 and all products starting with this pattern are displayed.- Save
Command to store changed values in the Qty. column. If you change a value and navigate to another page or leaving the application without choosing Save before, the value is not saved.
- Title
The tableViewDefinition bean provides methods to set the title.
- Table
The table is composed by two beans. The tableViewDefinition bean contains the header and color layout. The header contains a link which changes the sort order of the product ID column when clicked. An up or down icon indicates the current sort order.
The dataHandler bean provides the data. The first column is displayed as input field an contains the STOCK_CURRENT field value.
- Navigation
The tableViewDefinition bean provides methods to set the icons for navigation. The navigation is embedded in another form, so that we have access to the page input field.
Footer Panel
The tableViewDefinition bean provides to methods to set the text on the left and right hand side of the footer panel.
Java - default package |
Description |
ControllerServlet.java | Implementation of the servlet. Handles the events and sets the bean. |
Constants.java | Interface defining all text strings used in PersistenceExample.java. |
Java - dataAccess package |
Description |
SmartSyncDBAccess.java | Contains all calls to the SmartSync API. Points of interest is the getSynBoInstances() method that shows the usage of the SmartSyncQueryFactory. |
Java - bean package |
Description |
BasicDataHandler.java | This class handles the data. It is directly connected to the persistence classes in the datafactory package. When the user navigates to another page the BasicDataHandler takes care to get the proper data in a vector. This data is than displayed with the JSP. |
TableViewDefinition.java | Implementation of the bean that is loaded by the servlet and read by the JSP. It contains the layout information and text strings for the JSP. |
JSP |
Description |
menu.jsp | Initial JSP to display the SyncBo. |
query.jsp | JSP to enter a filter string. |
add.jsp | JSP to add an entry. |
savefailed.jsp | JSP to display an error message, when the saving of the quantity value failed. |
The user interface of the initial screen has a display area and three buttons:
We create a class ControllerServlet 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 ControllerServlet you will find the definition in interface Constants.
The class ControllerServlet extends AbstractMEHttpServlet which extends javax.servlet.http.HttpServlet itself. The application is separated into the default package (containing all classes necessary to interact with the user), the dataAccess package (containing all classes necessary to manipulate the persisted data) and bean package (which contains the bean which serves as data bag between the servlet and the JSP).
default package
start_index
that contains the current index from which the SyncBos are displayed.
According to the event that occurred we have updated the variables start_index
,
sort_ascending
or filter_string
and or a new entry.
Now we call the method to read all matching SyncBos.
private void getBeansFromContext(HttpServletRequest request)
Checks if there is already a bean in the session context. This would be the case if the servlet is called from an event of the web browser. If no bean is in the session context, that would be the initial call, a new bean instance is created.
This method always creates a new instance of the dataHandler. By doing that the iterator that contains all SyncBo to be displayed is up to date, according to the settings we did before according to the occurred events. This is the only time, we read the data from the MI client with the SmartSync API.
All matching SyncBos are kept in the MEIteratorsyncBos
in the BasicDataHandler.
Now comes the section were we check the other events occurred. The events come from:
- menu.jsp
Events occur when the "Add" "Set Filter/Reset Filter" or "Save" button has been chosen. For the "add" event we just define the add.jsp as next JSP page. For the "Set Filter/Reset Filter" event we just define the query.jsp as next JSP page. For the "Save" button we read the input fields from the form, check if a value has been changed and if so, modify it in the database of the MI client. This is done by method saveEntries().
There are some "Cancel" events to take care of. These events occur, when a user chooses the "Cancel" button in the add.jsp or query.jsp. In this case we just display the default page menu.jsp.- add.jsp
Can send an "addEntrySubmit" or "addEntryCancel" event. The "addEntryCancel" event is handled by defining the initial jsp (menu.jsp) as next JSP. When the "addEntrySubmit" event occurs, we retrieve the input fields of the add.jsp and call methods in thedatafactory
package to add the entry.- query.jsp
Can send a "querySubmit" or a "queryCancel" event. On both events the initial jsp (menu.jsp) is set as next JSP. The "querySubmit" event sets the filter string. In case of an empty filter string, the filter function is turned off.- savefailed.jsp
Is called only when the new values could not be saved. It contains an error message that informs the user.The next methods called are:
- public void loadBean(boolean listmode)
This method sets the header and footer panel and the command line. It gets the SyncBos to display and puts the data in the TableViewDefinition and BasicDataHandler bean.
- private void putBeansIntoContext(HttpServletRequest request)
Puts the bean in the session context so that it can be retrieved by the bean.
Now the JSP is called and the data is displayed on your web browser.
dataAccess package
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.
menu.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. It uses a table view to display the persisted
data. The table view has an input filed in the first row to change the quantity
of the item.
add.jsp
JSP with input fields to enter a new product. There are two buttons, "Add"
to add the entry and"Cancel" to go back to menu.jsp without adding
the entry.
query.jsp
JSP with an input fields to define a filter string. The a filter string is applied
to the "product ID". If you enter "0" as filter string,
only products with a product ID that starts with "0" are displayed
in menu.jsp. The query condition is made with the STARTSWITH option. If you
leave the input field empty and choose "OK", all entries are displayed.
When the "Cancel" button is clicked, the menu.jsp is displayed without
any changes.
savefailed.jsp
If the saving of the new values fails the user informed with an error message
in this JSP.