Onlinehjälpen

Script

The Script portlet has two parts - JavaScript and Velocity. JavaScript and makes all variables available in the Velocity part for easy rendering.

Elements available in the JavaScript context
NameType and Description
requestjavax.portlet.PortletRequest
 The portlet request
outjava.io.PrintWriter
 The output writer, use for output if you don't render your output in the Velocity part
Elements available in the Velocity context
NameType and Description
requestjavax.portlet.PortletRequest
 The portlet request
??
 An Object/value that was declared as a variable in the JavaScript part

Note! The JavaScript (and Velocity) is of course executed serverside!

Writing code in the Script portlet

Variables declared in the JavaScript part are accessible in the Velocity part. An example that uses the SiteVision Public API is shown below:

5 variables are declared in the JavaScript part above so there are 6 (request + 5) references available on the Velocity Context:

  • ​$request
  • $sitevisionUtils
  • $propUtil
  • $ctxUtil
  • $user
  • $name

Tip! If you are unfamiliar with Velocity, see our Velocity jumpstart section to get a quick introduction.

Creating Java objects

The "Packages" keyword and full package name must be used when creating Java objects in the JavaScript part. An example:

var now = new Packages.java.util.Date();

var number = 7;

The variable name for the JavaScript object/value can be accessed in the Velocity part.

$now

$number

Handling native JavaScript objects

Native JavaScript objects must be handled somewhat differently in the Velocity part. An example: If your JavaScript variable looks like this:

var company = { name : 'SiteVision AB' };

Then you can NOT access the name of the company object in Velocity via the "JavaScript syntax" like $company.name. You access it like this:

$company.get('name', $company)

Tip! Some syntax examples and return values can be found on the Mozilla Scriptable interface documentation External link, opens in new window..

Sidan uppdaterad:

Nästa generations publiceringsverktyg är här!

se-sto-pio-sv5-2.sitevision-cloud.net
3.135.205.164