JSMA request

Overview

The JSMA request allows to retrieve HTTP request specific informations. It also allows request scope based communication between macros.

What can JSMA request do for me?

The JSMA request allows to retrieve HTTP request specific informations like headers, url parts and the session id of the caller. It also allows request scope based communication between macros.

Index

Usage

Resolver Macro

This macro would be called at the beginning of a page to resolve a product and store it as request value for later use within other macros.

...
//resolve a product from a given GET or POST parameter 
var product = products.findByName(request.parameter("product"));
if (product) {
  //set the product in the request values
  request.set("myProduct", product);
}
...

Using macro

This macro retrieves the product from the request and uses it if it was set

... 
//retrieve the product from the request values
if (request.has("myProduct"))
{
  var product = request.get("myProduct");
  //do whatever has to be done ...
}
...

Methods

The JSMA request provides the following methods:

string request.get(key)

Returns the value of key as string or null if no value is set under the key.

Example

... 
if (request.has("myProduct")) 
{ 
   var product = request.get("myProduct"); 
   //do whatever has to be done ... 
}
...

Parameter key:string (required)

The key to be looked up in the flexAttributes of the request.

boolean request.has(key)

Returns a boolean value depending on whether key is present for this request.

Example

... 
if (request.has("myProduct")) 
{ 
  var product = request.get("myProduct"); 
  //do whatever has to be done ... 
}
...

Parameter key:string (required)

The key tob e checked in the flexAttributes of the request.

request.header(name)

Retrieves a header file from the HTTP request.

Example

... 
var uri = request.header.get("REQUEST_URI");
...

request.host

Returns the host part of the url of this request as it was passed to the application server.

Example

... 
var basePath = request.protocol + "://" + request.host;
...

request.parameter(name)

Returns a parameter which was either given as GET or as POST parameter. It returns null if it was not set in the request.

Example

... 
var size = request.parameter('size');
...

request.parameters

Returns a map of the parameters and their values as it was processed by the application server.

Example

... 
request.parameters
...

request.path

Returns the path part of the url of this request as it was passed to the application server.

Example

... 
request.path
...

request.protocol

Returns the protocol part (i.e. HTTP and HTTPS) of the url of this request as it was passed to the application server.

Example

... 
var basePath = request.protocol + "://" + request.host;
...

request.sessionId

Returns the sessionId

Example

... 
request.sessionId
...

request.set(key, value)

Sets a named value for the request which can be retrieved with get later in this request.

Example

... 
request.set(key, value)
...

Parameter key:string (required)

The key to be set in the flexAttributes of the request.

Parameter value:string (required)

The value to be set for the key