WebApps 2
AppData
Using AppData for HTML input elements
<!-- index.html -->
<input name="inputField"/>
Retrieving appData
Use appData
to retrieve values from the configuration.
// index.js
import appData from '@sitevision/api/server/appData';
const text = appData.get('inputField');
Using AppData for "native" Sitevision components
Values are retrieved the same way using the appData-object in a server side script context.
<!-- index.html -->
<div class="form-group">
<label>Page</label>
<input class="form-control" data-component="page-selector" name="page" />
</div>
<div class="form-group">
<label>Pages</label>
<input type="hidden" data-component="page-list" name="pages" />
</div>
// index.js
import appData from '@sitevision/api/server/appData';
// returns the JCR Node
const page = appData.getNode('page');
// returns the JCR Node identifier i.e: '4.540818ed12a6539aa3f80001645'
const pageId = appData.get('page');
/*
* returns an object with given properties of the JCR Node i.e:
*
* {
* URI: '/4.540818ed12a6539aa3f80001645.html',
* displayName: 'Home',
* published: true,
* publishDate: 1227618333142
* }
*/
const pageData = appData.get(
'page',
'URI',
'displayName',
'published',
'publishDate'
);
/* getArray
*
* returns value as an array
* - an array of JCR Nodes for list components
* - value wrapped in an array for single type components
*/
const pages = appData.getArray('pages');
AppData for the Sitevision metadata selector
The metadata selector manages a metadata definition. Though, in many cases the metadata value is of interest.
Tip! The metadata value for a specific node can be resolved using the name of the metadata definition.
<!-- index.html -->
<div class="form-group">
<select
class="form-control"
data-component="metadata-selector"
name="metadef"
></select>
</div>
// index.js
import appData from '@sitevision/api/server/appData';
import portletContextUtil from '@sitevision/api/server/PortletContextUtil';
import propertyUtil from '@sitevision/api/server/PropertyUtil';
// Get the metadata definition JCR Node
const metadataDefinition = appData.getNode('metadef');
// Get the name of the metadata definition and the Node of interest
const nameOfTheMetadata = metadataDefinition.getName();
const currentPage = portletContextUtil.getCurrentPage();
// ...and resolve the metadata value
const metadataValue = propertyUtil.getString(currentPage, nameOfTheMetadata);