Jump to content
  • This documentation is an older version of JasperReports Server Ultimate Guide. View the latest documentation.

    The action model is a complex mechanism for generating menus dynamically. In particular, menus in Ad Hoc must be generated programmatically based on the contents of the reports, for example the context menu on a column. The following high-level steps explain how menus are generated:

    When generating menus, the Ad Hoc Editor follows these steps:

    1. Whenever a page with menus is to be displayed for the first time, the server looks up the corresponding action model XML definition and uses JDOM (Java-based Document Object Model for XML) to build and cache a Document.
    2. Subsequent viewings reference the cached Document.
    3. After the page is modified (usually triggered by an Ajax Request) the server generates a client side action model in the form of a JSON expression. Based on the current page state, the client model is a filtered version of the full action model in which internationalized names and generated options are resolved, and so forth.
    4. Every time a menu is requested on the client, the server looks up the context in the JSON model, and for each action, clones the appropriate HTML template for the menu and tweaks its attributes accordingly.

    note-icon-ns_28x28.png.52e88c01f8a74fdd235159c20656565b.png

    Some pages have mostly static menus that don’t change based on page contents. Other pages, such as the Ad Hoc Editor, have dynamic menus that are updated in this way in response to changes the user makes on a page.

    The following sections document the XML elements used in the action model definition files. In particular, you can define various conditions at several levels so menus appear only to certain users or based on the current state of the page.

    Context

    Each context represents a distinct menu type and refers to the part of the design page that launches that menu. Examples are reportLevel, columnLevel, fieldLevel. They're directly equivalent to the menu levels defined in the popup-style JSP files used in previous releases.

    Condition

    A condition element invokes the specified server side test as a method on the view model. The enclosed actions are included in the client action model only if the test returns true.

    If the test has a leading exclamation point (!), the condition tests for false:

    test – The name of the java method to be invoked on the view model.
    testArgs – Array of parameters to be passed to the above test, expressed as a comma-separated string.

    Actions

    Each defined action produces one or more rows in the generated menu. The following tables describe the several action types.

    simpleAction

    A standalone menu action that, when clicked, fires the specified JavaScript method.

    Attributes

    The ID of the menu row DOM object.

    If set to true, disable this row initially (shows a gray block instead).

    The text the menu should display. If it corresponds to an localization bundle key it is translated, otherwise it is displayed as is.

    Sometimes the label value is contingent on the current state. The label condition references a Java method on the view model and should return a Boolean. A labelCondition defines two labelOption sub elements (see below).

    Only generate a row for this action if it passes the specified JavaScript method.

    If the clientTest has a leading exclamation point (!), tests for false.

    An array of parameters pass to the above test, expressed as a comma delimited string.

    The JavaScript method to be fired when the action is taken.

    An array of parameters to be passed to the above test, expressed as a string delimited by the @@ string constant.

    If true the menu stays displayed after action.

    separator

    Not strictly an action. Outputs a separator bar. The style of the bar automatically adjusts to the current nesting level.

    Attributes

    Only generate a row for this action if it passes the specified JavaScript method.

    An array of parameters to be passed to the above test, expressed as a string delimited by the @@ string constant.

    Disable this row initially (shows a gray block instead).

    selectAction

    A drop down (roll down) parent. Selectors can be nested up to three levels deep. The menu automatically renders the roll-downs in a nested fashion.

    Attributes

    If set to true, disable this row initially (shows a gray block instead).

    If set to true, selector is opened initially.

    The text for the menu to display. If it corresponds to an localization bundle key it is translated, otherwise it is displayed as is.

    Sometimes the label value is contingent on the current state. The label condition references a java method on the view model and should return a Boolean. A labelCondition defines two labelOption sub elements (see below).

    Only generate a row for this action if it passes the specified JavaScript method.

    An array of parameters to be passed to the above test, expressed as a string delimited by the @@ string constant.

    Options

    Some actions can have child elements, as described in the following tables.

    option

    Child of selectAction. Defines a static menu option. Use this when you can't define options programmatically.

    Attributes

    The ID of the menu row DOM object.

    If set to true, disable this row initially (shows a gray block instead).

    If set to true the option displayed as a button (as in formula builder).

    The text for the menu to display. If it corresponds to an localization bundle key it is translated, otherwise it is displayed as is.

    Sometimes the label value is contingent on the current state. The label condition references a java method on the view model and should return a Boolean. A labelCondition defines two labelOption sub elements (see below).

    Only generate a row for this action if it passes the specified JavaScript method.

    An array of parameters to be passed to the above test, expressed as a comma delimited string.

    Show an input box in this option if it passes the specified JavaScript method.

    An array of parameters to be passed to the above test, expressed as a string delimited by the @@ string constant.

    The JavaScript method to be fired when the action is taken.

    An array of parameters to be passed to the above test, expressed as a comma delimited string.

    Indicate a check mark next to this option if it passes the specified JavaScript method.

    An array of parameters to be passed to the above test, expressed as a string delimited by the @@ string constant.

    generatedOptions

    Child of selectAction. Defines a set of dynamically-defined options.

    Reserved Variables (in addition to standard reserved variables)

    Programmatically assigned ID. If function returns a Map this is the key part of each key-value pair, if it returns a Collection it is the toString value of each element.

    Programmatically assigned display value. If function returns a Map this is the value part of each key-value pair, if it returns a Collection it is the toString value of each element.

    When used in a label expression attempts to internationalize the enclosed String and if it fails it returns the literal value.

    Attributes

    The ID of the menu row DOM object.

    The name of the java method to invoke on the view model that is used to generate the options. The function can return either a Map or a Collection. The type of object returned affects how the ${optionValue} and ${optionId} reserved variables are interpreted (see above).

    An array of parameters to pass to the above test, expressed as a string delimited by the @@ string constant.

    The text for the menu to display. If it corresponds to an localization bundle key it is translated, otherwise it is displayed as is.

    Sometimes the label value is contingent on the current state. The label condition references a java method on the view model and should return a Boolean. A labelCondition defines two labelOption sub elements (see below).

    Allows a custom label to be defined and allows full use of all reserved variables. (for example, labelExpression="${optionValue}") $R{ADH_252_DATA_ROWS}").

    Only generate a row for this action if it passes the specified JavaScript method.

    An array of parameters to be passed to the above test, expressed as a string delimited by the @@ string constant. If no actionArgs are specified, the ${optionId} variable is automatically assigned as an argument.

    Show an input box in this option if it passes the specified JavaScript method.

    An array of parameters to be passed to the above test, expressed as a string delimited by the @@ string constant. If no actionArgs are specified, the ${optionId} variable is automatically assigned as an argument.

    The JavaScript method to be fired when the action is taken.

    An array of parameters to be passed to the above test, expressed as a comma delimited string. If no actionArgs are specified, the ${optionId} variable is automatically be assigned as an argument.

    If true the menu stays displayed after action (for all generated options).

    Indicate a check mark next to this option if it passes the specified JavaScript method.

    An array of parameters to be passed to the above test, expressed as a string delimited by the @@ string constant. If no actionArgs are specified, the ${optionId} variable is automatically assigned as an argument.

    Default Settings (DOM attributes set automatically on each generated Option)

    If not specified as an a attribute defaults to the ${optionId} variable.

    If not specified as an a attribute defaults to the ${optionId} variable.

    If not specified as an a attribute defaults to the ${optionId} variable.

    If not specified as an a attribute defaults to the ${optionId} variable.

    labelOption

    Child of labelFunction. Every labelFunction element should have two labelOption elements as children. One of them is used to define the action label depending on the result of the labelCondition.

    Attributes

    A Boolean string. If the parent labelCondition result matches this Boolean value, this labelOption is used.

    The text for the menu to display. If it corresponds to an localization bundle key it is translated, otherwise it is displayed as isgenerateFromTemplate.

    generateFromTemplate

    Programmatically generates multiple actions by specifying a function to iterate over the enclosed template. The template can be any valid action structure, it can include multiple actions and/or nested actions.

    Reserved Variables (in addition to standard reserved variables)

    The zero-based index of the current iteration.

    Programmatically assigned ID. If function returns a Map this is the key part of each key-value pair, if it returns a Collection it is the toString value of each element.

    Programmatically assigned value. If function returns a Map this is the value part of each key-value pair, if it returns a Collection it is the toString value of each element.

    Attributes

    The name of the java method to be invoked on the view model that is used as the template iterator. The function can return either a Map or a Collection. The type of object returned affects how the reserved variables ${templateInjectionId} and ${templateInjectionValue} are interpreted (see above).

    An array of parameters to be passed to the above test, expressed as a string delimited by the @@ string constant.

    Child Elements

    Any valid action structure, which is used as the template.

    Special Expressions

    The following special expressions are converted to built-in variable values when used as arguments for client functions:

    Expression

    Definition

    The JavaScript array of selected objects on the client.

    The JavaScript event object.

    The generated label for this menu.

    Menu DHTML API

    This is a set of JavaScript functions defined on actionModel.js to dynamically manipulate a menu’s look and feel after it's been displayed. You can use them to change the Ad Hoc Editor menus in run-time. Most of them take the menuRow or the menuRow’s identifier as arguments. Some have additional arguments as well. For more information about the additional arguments, refer to the code itself.

    Function

    Description

    Hide the input box on the option.

    Show the input box on the option.

    Set the backgroundColor to the specified color.

    Restore original background color.

    Return the current label for this row.

    Set the label for this row.

    Grey out the row.

    Restore the row to active state.


    User Feedback

    Recommended Comments

    There are no comments to display.



    Guest
    This is now closed for further comments

×
×
  • Create New...