The Script portlet has two parts - JavaScript and Velocity. JavaScript and makes all variables available in the Velocity part for easy rendering.
Name | Type and Description |
---|---|
request | javax.portlet.PortletRequest |
The portlet request | |
out | java.io.PrintWriter |
The output writer, use for output if you don't render your output in the Velocity part |
Name | Type and Description |
---|---|
request | javax.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!
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:
Tip! If you are unfamiliar with Velocity, see our Velocity jumpstart section to get a quick introduction.
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
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!