skip to main content
Programmer's documentation > Building Web Applications > Developing basic JViews JavaScript Web applications > Adding client/server interactions
 
Adding client/server interactions
Overview of actions on the server and client sides
The Rogue Wave® JViews JavaScript Web application support gives you a simplified way to define new actions that should take place on the server side. For example, suppose you want to allow the user to delete a graphic object that appears on the generated image. Part of this action—clicking the image to select the object—must be done on the client side. The destruction of the object must be done on the server side before a new image is generated. The notion of “server-side action” exists to perform such behavior. An action is defined by a name and a set of string parameters.
Actions on the client side
In a JavaScript client, you tell the server to perform an action using the performAction method of the IlvView JavaScript™ component.
Here is an example that asks the server side to execute the action “delete” with coordinate parameters, assuming that view is an IlvView:
 
var x = 100;
var y = 50;
var params = new Array();
params[0]=x;
params[1]=y;
view.performAction(“delete”, params);
In a thin-Java client the system is the same:
float x = 100f;
float y = 50f;
String[] params = new String[2];
params[0] = Float.toString(x);
params[1] = Float.toString(y);
view.performAction(“delete”, params);
The performAction method ask the server for a new image. In the image request, additional parameters are added so that the server side can execute the action. Thus, the performAction call results in only one client/server round-trip.
Note that predefined interactors are provided to help you define new actions on the client side. They are explained in Predefined interactors.
Actions on the server side
On the server side, you need to detect that an action was requested and execute the action. This is done using the interface ServerActionListener.
To be able to listen and execute an action on the server side, you simply add an action listener to your servlet. In the performAction method of the listener, you check the action name and perform the action.
For the “delete” action, add the following lines of code in the init method of the servlet:
 
addServerActionListener(new ServerActionListener() {
   public void actionPerformed(ServerActionEvent e) throws ServletException
  {
    if (e.getActionName().equals("delete")) {
      IlvPoint p = e.getPointParameter(0);
        // find object under this point and delete it if there is one.
    }
  }
});
The ServerActionEvent object can give you all necessary information about the action, the name, and its parameters.
Predefined interactors
Two predefined interactors are provided to help you create new actions: IlvMapInteractor and IlvMapRectInteractor.
IlvMapInteractor allows the user to click in the map; it asks the server to execute an action, with the coordinates of the clicked point passed as parameters. The second interactor is almost the same except that the user selects an area of the image instead of clicking on it.

Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.