SiteVision Onlinehelp
Search

Script field

The custom templates in the script field uses the JCR (Java Content Repository, JSR 283) programming model. The SiteVision API is available here
Configuration of subscript field using reference subscriptRefZoom image
Subscripts are available as subnodes on ths scriptfield.
More information about properties available on subscripts can be found in the Public API section.
The JavaScript and Velocity context also contains two maps containing values and messages associated with the sub script fields.
NameType and Description
valuesjava.util.Map
 A map containing values associated with subscript fields. The key should be a subscript field and the corresponding value is either a String or a String[] object. An IllegalArgumentException will be thrown if any other object is used with the methods in the map.
messagesjava.util.Map
 A map containing messages associated with subscripts fields. The key is a subscript field and the corresponding value is a String object. An IllegalArgumentException will be thrown if any other is used with the methods in the map.

Field input rendering


Templates specified here is used when rendering the form that users should fill out and submit. The JavaScript is executed first and can therefore be used when populating default values and the Velocity template is used afterwards to generate the HTML code containg input tags.
#set ($propertyUtil = $sitevisionUtils.propertyUtil)
#set ($endecUtil = $sitevisionUtils.endecUtil)
#set ($labelFont = $propertyUtil.getNestedString($portlet, 'labelFont', 'selectorText'))
#set ($inputFont = $propertyUtil.getNestedString($portlet, 'inputFont', 'selectorText'))
#set ($errorFont = $propertyUtil.getNestedString($portlet, 'errorFont', 'selectorText'))

##
## Get the subscript reference
#set ($subscriptRef = $portlet.getNode("Form/MyScriptField/MySubscript") )

##
## Get properties from subscript
#set ($id = $propertyUtil.getString($subscriptRef, "id"))
#set ($type = $propertyUtil.getString($subscriptRef, "type"))
#set ($question = $propertyUtil.getString($subscriptRef,"question",""))

##
## Render label
<label class="$labelFont" for="$id">$question</label>
<br />

##
## Render input tag avoiding XSS problems
#if ($values.containsKey($subscriptRef))
   #set ($value = $values.get($subscriptRef))
#else
   #set ($value = "")
#end
<input class="$inputFont" id="$id" name="$id" type="$type" value="$endecUtil.escapeXML($value)"/>
<br />

##
## Render error message (if any)
#if ($messages.containsKey($subscriptRef))
   <span class="$errorFont">$messages.get($subscriptRef)</span>
   <br />
#end

Validation of values


If this script is activated is it possible to create an own JavaScript that validates the values submitted by users. A re-rendering of the form can be triggered by associating an error message with one or more subscript(s).
if (!values.containsKey(subscriptRef))
{
   messages.put(subscriptRef, "A value must be entered here!");
}
During validation is it also possible to associate values with subscript(s). This feature can be used when we want to associate values with subscript(s) that is provided by SiteVision (or another system) and not the user. An example of this could be attribute stored in the portlet request.
// Get personal number from portlet request (added by third party system)
pnr = request.getAttribute("pnr");
if(pnr != null)
{
   // Something is very wrong, a pnr should always exist in the request
   messages.put(subscriptRef, "No personal number was found!");
}else
{
   values.put(subscriptRef, pnr);
}

Last updated:

se-sto-ste-sv5-1.sitevision-cloud.net
3.128.199.162