public class CreateWebScriptWidgetsDirective extends JavaScriptDependencyDirective
This directive should be used in WebScripts that intend use client-side JavaScript "widgets". The directive relies upon the following specific data having been added to the model. All widget data should be placed in a "webScriptWidgets" array. Each element in the array should contain the following properties:
| Modifier and Type | Class and Description |
|---|---|
protected class |
CreateWebScriptWidgetsDirective.WidgetData
Contains the data that defines a JavaScript widget to be instantiated.
|
AbstractDependencyExtensibilityDirective.ProcessedDependency| Modifier and Type | Field and Description |
|---|---|
static String |
REFERENCE_TYPE_KEY
This constant is used as one of the two attributes that specify custom options (the other being
REFERENCE_TYPE_KEY)
if a Map is supplied as value that only contains these two attributes then it is considered a custom options and is
processed by the processCustomOption method. |
static String |
REFERENCE_VALUE_KEY
This constant is used as one of the two attributes that specify custom options (the other being
REFERENCE_TYPE_KEY)
if a Map is supplied as value that only contains these two attributes then it is considered a custom options and is
processed by the processCustomOption method. |
FORCE_AGGREGATED_OUTPUT_PARAMdependencyAggregator, dependencyHandler| Constructor and Description |
|---|
CreateWebScriptWidgetsDirective(String directiveName,
org.springframework.extensions.surf.extensibility.ExtensibilityModel model) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
addLegacyDependencyRequest(Map params)
This is simply overridden to prevent the "src" not found error being generated.
|
protected List<CreateWebScriptWidgetsDirective.WidgetData> |
buildWidgetDataList(freemarker.template.TemplateHashModel model) |
protected String |
buildWidgetInstantiatationScript(freemarker.core.Environment env,
CreateWebScriptWidgetsDirective.WidgetData widget,
String htmlId,
String messages)
Constructs a String of JavaScript that can be used to instantiate the widget defined by the
supplied
CreateWebScriptWidgetsDirective.WidgetData objects. |
org.springframework.extensions.surf.extensibility.ExtensibilityDirectiveData |
createExtensibilityDirectiveData(String id,
String action,
String target,
Map params,
freemarker.template.TemplateDirectiveBody body,
freemarker.core.Environment env) |
protected org.springframework.extensions.webscripts.json.RawValue |
processCustomOption(freemarker.core.Environment env,
Map<String,Object> customOption)
This method is provided to allow extending classes to process custom options other than the
default ReferenceCustomOption that is used to render variable references instead of
String literals.
|
protected Map<Object,Object> |
processCustomOptionsInMap(freemarker.core.Environment env,
Map<Object,Object> options)
In order to distinguish between genuine Strings and value references in the options map
it is necessary to process all the String values.
|
protected Object |
processCustomOptionsInObject(freemarker.core.Environment env,
Object object)
Processes any custom options that are found in the supplied object.
|
createDependencyDirectiveData, execute, getDependencySource, getTargetElementgetModelObject, getRequestContext, getResourceControllerMapping, getToInsert, getUpdatedSrc, getWebFrameworkConfig, processDependency, setDependencyAggregator, setDependencyHandler, setModelObject, setRequestContext, setWebFrameworkConfigafter, before, getId, getModel, merge, remove, replacepublic static final String REFERENCE_VALUE_KEY
REFERENCE_TYPE_KEY)
if a Map is supplied as value that only contains these two attributes then it is considered a custom options and is
processed by the processCustomOption method. By default the value associated with the key in the Map
will be used as a reference to a JavaScript variable.public static final String REFERENCE_TYPE_KEY
REFERENCE_TYPE_KEY)
if a Map is supplied as value that only contains these two attributes then it is considered a custom options and is
processed by the processCustomOption method. The value associated with the key in the Map is not actually
used in the default implementation of CreateWebScriptWidgetsDirective (other than as a marker to indicate a custom
option) but can be used by extending classes that wish to handle other custom options.public CreateWebScriptWidgetsDirective(String directiveName, org.springframework.extensions.surf.extensibility.ExtensibilityModel model)
protected void addLegacyDependencyRequest(Map params) throws freemarker.template.TemplateModelException
addLegacyDependencyRequest in class JavaScriptDependencyDirectiveparams - Mapfreemarker.template.TemplateModelExceptionpublic org.springframework.extensions.surf.extensibility.ExtensibilityDirectiveData createExtensibilityDirectiveData(String id, String action, String target, Map params, freemarker.template.TemplateDirectiveBody body, freemarker.core.Environment env) throws freemarker.template.TemplateException
createExtensibilityDirectiveData in class JavaScriptDependencyDirectivefreemarker.template.TemplateExceptionprotected String buildWidgetInstantiatationScript(freemarker.core.Environment env, CreateWebScriptWidgetsDirective.WidgetData widget, String htmlId, String messages)
Constructs a String of JavaScript that can be used to instantiate the widget defined by the
supplied CreateWebScriptWidgetsDirective.WidgetData objects. The output will be a single line of JavaScript with chained
.setOptions() and .setMessages() functions calls if appropriate.
env - Environmentwidget - The CreateWebScriptWidgetsDirective.WidgetData object containing the data about the widget to be instantiated.htmlId - The current unique id of an HTML <div> element that should have been placed in the
WebScript FreeMarker template for the JavaScript widget to attach to.messages - The current i18n message object for the current request.protected Map<Object,Object> processCustomOptionsInMap(freemarker.core.Environment env, Map<Object,Object> options)
In order to distinguish between genuine Strings and value references in the options map it is necessary to process all the String values. This method works through the map (which could have have nested lists and maps as values) and converts all Strings to either StringOption or ReferenceOption instances. This is done so that when the options map is converted into a JSON string it will fall back on the .toString() method of the unknown type which we can therefore control.
env - Environmentoptions - Mapprotected Object processCustomOptionsInObject(freemarker.core.Environment env, Object object)
Processes any custom options that are found in the supplied object. The supplied object will either
be a Map a List or some other valid JSON value (e.g. a String, a boolean, etc). Custom
options are defined as a Map containing two special attributes (and only those two attributes)
so this method will check all Map instances for those attributes and return a JSONAware
object in their place for outputting. Otherwise the method will recurse through all the objects.
env - Environmentobject - Objectprotected org.springframework.extensions.webscripts.json.RawValue processCustomOption(freemarker.core.Environment env,
Map<String,Object> customOption)
This method is provided to allow extending classes to process custom options other than the
default ReferenceCustomOption that is used to render variable references instead of
String literals. It should be called with a Map containing two entries; the
value and the type. This implementation will only return a ReferenceCustomOption
instance.
env - The current FreeMarker Environment. Not used by this implementation but
provided for the benefit of extending classes.customOption - A Map containing value and type for the custom option.JSONAware object.protected List<CreateWebScriptWidgetsDirective.WidgetData> buildWidgetDataList(freemarker.template.TemplateHashModel model) throws freemarker.template.TemplateModelException
model - TemplateHashModelfreemarker.template.TemplateModelExceptionCopyright © 2005–2016 Alfresco Software. All rights reserved.