Startseite
Startseite

Startseite / Plugin-Entwicklung / ContentCreator-Erweiterungen / Interaktive Features / Interaktive Buttons (Vorlagen) / Codebeispiel

Template Buttons: Code Example

Implementing interactive preview functionality using the input component FS_BUTTON requires template modifications as well as authoring of scripts and/or executables that will be called when users interact with a button representation.

As the FS_BUTTON's definition in FirstSpirit templates is already authoritatively described in the section Template Development: FS_BUTTON, this chapter concerns itself primarily with creating executable functionality to handle click and drag-and-drop operations in Java classes.

Template Definitions

Settings in the Template Form

The primary receivers of data via drag-and-drop are FS_BUTTON instances rendered in ContentCreator's page preview. Within a template form, the FS_BUTTON may be configured to call a drop handler script or executable if a drop action has occurred by specifying that handler in the onDrop attribute.

  • Scripts stored in the Template Store may be referenced simply with the attribute value
    script:ScriptUid
  • Java classes provided by a FirstSpirit Module must be referenced by fully qualified class name, such as
    class:de.espirit.firstspirit.opt.example.webedit.report.TextBlocksDropHandlerExecutable

Both scripts and classes receive a number of information objects regarding the FS_BUTTON interaction, including an indicator whether the handler has been called in the context of a click or a drop action, several items regarding the current button context as well as a container for drop data that may hold various data for different transfer types. The information items provided to handler executables is described in the section Template Development: Forms: FS_BUTTON.

Important If a Beanshell script is used to handle an FS_BUTTON drop operation, the script's environment is prepared during setup so that the information items are instantiated as individual variables.

Drop handlers implemented in Java code an included as ContentCreator plug-ins must obtain these information items from the context object passed to the class' execute() method (see below).

Rendering an FS_BUTTON in the Preview

An FS_BUTTON may be rendered in the ContentCreator preview by placing code such as the following in the appropriate output channel definition of the template:

$CMS_VALUE(
fsbutton(
editorName:"fs_button_component_name",
parameter:{
"page":#global.page.id,
"body":"Content"
}
)
)$

Button Actions

Accessing Context Information

FS_BUTTON actions are implemented using native Java classes or Beanshell scripts. Both of these execution types gain access to the same context information:

Context Information

Object Type

Description

Access in Java Class (Type Executable)

Access in Beanshell Script

Button Context

BaseContext

allows access to agents and other FirstSpirit information

call
(BaseContext)
context.get("context");

variable context

Button Properties

Map<String, String>

provides all properties (also called parameters) defined for this FS_BUTTON in the template form or output channel

call
(Map<String, String>)
context.get("properties");

variable properties

Context Element

IDProvider

provides the store element that is associated with a button instance (i.e., in whose template the FS_BUTTON is defined)

call
(IDProvider)
context.get("element");

variable element

Context Element Language

Language

indicates the project language of the form or preview the action was started in

call
(Language)
context.get("language");

variable language

Drop Indicator

Boolean

indicates whether the current action handles a click (false) or a drop action (true)

call
(Boolean)
context.get("drop");

variable drop

Drop Data
only available when handling a drop action

CommodityContainer

provides the object that was dropped onto the button instance; this object data will be obtained by requesting a specific content type

call
(CommodityContainer)
context.get("dropdata");

variable dropdata

     
Important Note that the context object passed into an Executable implementation's execute() methods is a Map with a String key and an Object value. Because the value of a map item is not typed explicitly, it is important to correctly cast the object returned by context.get().

Accessing Drop Data

Details on handling drop data are documented separately in the section Using FirstSpirit APIs: Drag-and-Drop.

© 2005 - 2015 e-Spirit AG | Alle Rechte vorbehalten. | Letzte Änderung: 2013-12-09