skip to main content
Charts > Programmer's documentation > Building Web Applications > Developing JViews Charts JavaScript Web applications > Server actions
 
Server actions
The JViews Charts 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 change the legend visibility from its browser. Changing the legend visibility must be done on the server side before a new image is generated. The notion of a "server-side action" exists to perform such behavior. An action is defined by a name and a set of string parameters.
On the client side, you tell the server to execute an action by sending an image request with the “action” parameter set. The value of this parameter is the action name concatenated with an in-parenthesis-comma-separated list of the required parameters. For example, the following request executes the LegendVisibilityAction action with the expected visibility as a parameter:
On the server side, you detect that an action was requested and you execute the action before the image is generated by implementing the IlvChartServerAction interface. To listen for an action request from the client and execute the action on the server side, you register the action with your instance of IlvChartServletSupport using the addServerAction method.
Server actions can be executed at two different times: either when the request has been just received before anything else, or just before the image is generated. In the first case, the actions are executed in the request thread, allowing you to execute actions that would typically be time-consuming and/or do not modify the visual appearance of the chart. In the second case, the actions are executed in the event dispatch thread. You specify in which thread an action should be executed by implementing the IlvChartServerAction.getExecutingThread method.
For example, the corresponding implementation of the LegendVisibilityAction is:
 
class LegendVisibilityAction implements IlvChartServerAction
{
    /** The action name. */
    static final String ACTION_NAME = "LegendVisibilityAction";
 
    public void actionPerformed(IlvChartServerActionEvent event)
      throws ServletException
    {
       boolean visible =
            Boolean.valueOf(
                      event.getParameters()[0]).booleanValue();
       event.getChart().setLegendVisible(visible);
    }
 
    public int getExecutionThread()
    {
        return IlvChartServerAction.SWING_EVENT_THREAD;
    }
}

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