AbstractDynamicMenu class

Abstract implementation of the dynamic menu state.

Syntax

public class AbstractDynamicMenu

Remarks

Typically extended by the states that needs to return a list of items. The list is sent to the mobile handset as Send SMS, and in the form of a menu, as shown on the following example.

    Transactions:
    1. 26 Jan 2012 09:16 - USD 10.00 Pay cab
    2. 26 Jan 2012 10:10 - USD 3.45  Starbucks
    3. 26 Jan 2012 12:25 - USD 20.00 Lunch
    4. 26 Jan 2012 13:30 - USD 3.00 Starbucks
    9: More
    0: Exit

The menu item can be selected by sending reply with the menu item number. Example, 1, 2, 3, or 4, to select the item; 9 will be shown when they are more items and selecting 9 will show them, 0 is for exiting from the menu and proceed to the alternative flow. Typically, when the menu item is selected, a more detailed information of the selected item will be sent as SMS.

If there are more items then those displayed, the paging menu item will be displayed. For the above example, it is "9: More". When 9 is sent back as the reply, the menu will refreshed showing the next page of the menu, and so on. The menu index is always starting from 1. When the menu reaches the end, and the 9 is sent back as a reply again, the menu will rotate back to the first page.

The state can be configured to show the exit menu item. In the above case, it's the "0: Exit". When 0 is sent back as a reply, nothing is selected so the state will continue the transition that is associated with the dynamic "EXIT" value. In some application flows, when a selection is required, the exit menu item can be suppressed by setting "No" to the "Show Exit menu" drop down box in the state editor.

Three Attribute are automatically registered by this class, including:
  • SelectionBoxAttribute - to specify whether to Show Exit menu item
  • OutputAttribute - to specify the variable name to store the selected menu KEY
  • OutputAttribute - to specify the variable name to store the selected menu VALUE

The life cycle of AbstractDynamicMenu is based on the life cycle of the SmappStatePlugin and StatePlugin with the following customizations to meet the menu functionalities.

AbstractDynamicMenu is just an abstract implementation of a state that can Send SMS in the form menu. The subclass provides implementation of getting the list for the menu. The processMessageLogic(SmappStateProcessingContext) and processStateLogic(SmappStateProcessingContext, SmappStateProcessingAction) methods have been final because they have the implementation for the menu functionalities. The subclass need to implement the following abstract methods instead: init(SmappStateProcessingAction), constructMenuList(), getStateAttributeList(), and saveSessionVariables(String, String).

  • init(SmappStateProcessingAction) method will be called by the processStateLogic(SmappStateProcessingContext, SmappStateProcessingAction).Please refer to the method description for details.
  • constructMenuList() and saveSessionVariables(String, String) methods will be called by both the processMessageLogic(SmappStateProcessingContext) and processStateLogic(SmappStateProcessingContext, SmappStateProcessingAction) methods.Please refer to the method description for details.
  • getStateAttributeList() is called from the getStateAttributes() that will aggregate the attributes returned by the getStateAttributeList() with some attributes defined in this abstract class for the menu, such as the input attribute for specifying whether to show the exit menu item, the output attributes for the key and value of the selected menu item.
  • The AbstractDynamicMenu state will initially be activated by the follow-up transition from a previous state, so the processing engine will call the processStateLogic(SmappStateProcessingContext, SmappStateProcessingAction) method. The init and constructMenuList method will be called sequentially to initialize and construct the menu. Eventually the menu will be sent out as SMS message, and the processing engine will be set to action.waitForMessage() waiting for the reply message. In this case, the user selects a menu item.
  • In the special case when the constructMenuList returns a single item only, the state will immediately call the saveSessionVariables(String, String) method proceed with the the default continueDyn(1) follow-up transition. The state can customized the default behavior by overriding the continueWhenSingleEntry(SmappState) method.
  • When the reply message arrives, the processing engine will trigger the AbstractDynamicMenu state using the external activation, hence calling the processMessageLogic(SmappStateProcessingContext) method.The constructMenuList method will be called again to assemble the menu that will be used to interpret the user selected menu index. If the selection is one of the valid menu item, saveSessionVariables(String, String) method will be called allowing the state to prepare all the select item details for output, and proceed with the follow-up transition as returned by the saveSessionVariables method. If null is null, the default OK follow-up transition will be used.