Response Class Methods

In this section, we discuss the Response class methods. The methods are discussed in alphabetical order.

Syntax

Clear()

Description

This method removes all cookies and headers as well as deletes any HTML that has been written to the Response object. After using this method, the Response object appears as it did when the script was first called.

Syntax

CreateCookie(name)

Description

This method adds a cookie to the response with the name specified by the string name. It returns a reference to the cookie object that is used to update the values of this cookie. If the cookie by the specified name already exists, a reference to the existing cookie is returned. This method can be called multiple times to set more than one cookie. Cookie names may not contain the "$" character.

Important! Certain browsers have limit of either 20 or 50 cookies per web server domain depending on the browser security update that the user has applied. The browser randomly discards some cookies when that number is exceeded.

PeopleTools uses eight cookies. In addition, the number of cookies used by PeopleTools can grow depending on the number of sites that the user visits within the same domain. Some PeopleSoft applications use additional cookies. Therefore, you might or might not be able to create your own cookies to modify an existing PeopleSoft application. If you do create your own cookies, keep the use conservative. Otherwise, your application might end up causing the browser to discard critical signon or authentication cookies.

More information about browser limitations can be found online.

See “Troubleshooting Browser Limitations” on My Oracle Support.

Syntax

GetCookie(name)

Description

This method returns the cookie object specified by the string name. If the cookie is not already present in this response, a null value is returned.

Syntax

GetCookieNames()

Description

This method returns an array of strings that contains the names of all the cookies present in this response. If there are no cookies in the response, an empty array is returned.

Syntax

GetHeader(name)

Description

This method returns the value of the response header requested by the string name. The match between name and the response header is case-insensitive. If the header requested does not exist, an empty string is returned.

Syntax

GetHeaderNames()

Description

This method returns an array of Strings representing the header names for this response.

Syntax

GetImageURL(IMAGE.ImageName | rowset.row.record)

Description

This method returns a string which represents the URL of the requested image for images stored in the database.

Because the image field is a long data type, you can have only one on a record. Therefore you need to specify the record only. The long field on the record is assumed to be the image.

Note: The GetImageURL method cannot be used with a derived work record.

Parameters

Field or Control

Definition

ImageName

Specify the name of an existing image. This name must be prefaced with the reserved word IMAGE.

rowset.row.record

Specify the path to the image, that is, the rowset, row, and record.

Example

The following example gets the URL to use for the image; and the second line uses the URL reference.

&image_URL = %Response.GetImageURL(Image.ARROW);

%Response.WriteLine("<img src=" | &strImage | ">");

The following gets an image from a record.

&image_URL = %Response.GetImageURL(&rs.GetRow(1).GetRecord(Record.EMPL_PHOTO));

Syntax

GetJavaScriptURL(HTML.HTMLname)

Description

This method returns a string which represents the URL of the requested HTML definition, for JavaScript HTML definitions stored in the database.

Example

This example assumes the existence in the database of an HTML definition called "HelloWorld_JS", that contains some JavaScript.

Function IScript_TestJavaScript() 
 
   %Response.WriteLine("<script src= " | %Response.GetJavaScriptURL(HTML.HelloWorld_JS) | "></script>");   

End-Function;

In this example, the HTML definition is called FOO. The following PeopleCode example:

%Response.GetJavaScriptURL(HTML.FOO)

Resolves to something similar to:

http://myserver/cache/js/FOO_ENG_1.js

Syntax

GetStyleSheetURL(STYLESHEET.stylename)

Description

This method returns a URL string pointing to a style sheet created in Application Designer.

Example

In the following example, the first line gets the URL to use for the style sheet, and the second is the standard HTML to include the style sheet in the HTML document. The stylesheet link must be included in the HTML before any of the styles in the stylesheet are used. It should be included in the <head> section of the HTML document.

&strStyleSheet = %Response.GetStyleSheetURL(StyleSheet.BENEFITS_STYLE);

%Response.WriteLine("<link rel=stylesheet href=" | &strStyleSheet | " type=""text/css"">");

Now to use a style, assign the class attribute of your choice to your HTML tags, as follows:

%Response.WriteLine("<p class=PSTEXT>I am some classy text!!</p>");

Syntax

RedirectURL(URL)

Description

Use the RedirectURL function to navigate to the location specified by the URL parameter. The given location must be an absolute URL. No further output should be made by the PeopleCode program after calling this method.

Note: This function does not issue any kind of warning to the user about losing data. Your application should verify that all data is saved before launching a new page.

Note: If your URL string contains special characters (such as foreign characters) make sure you encode it first using the EncodeURL function, such as, %Response.RedirectURL(EncodeUrl(&Url)).

In addition, while you can redirect relative URLs in certain circumstances, you cannot encode them.

Parameters

Field or Control

Definition

URL

Specify the location to navigate to as a string value.

Example

The following two examples demonstrate how to generate the URL string for component content:

/* Example 1 */
&url = GenerateComponentContentURL(%Portal, %Node, MenuName.GP_WC_FL_MNU, "GBL", Component.GP_WC_PYRL_STG_FL, Page.GP_WC_PAYRL_STG_FL, "U");
%Response.RedirectURL(&url);

/* Example 2 */
&url = GenerateComponentPortalURL(%IntBroker.DefaultPortalName(), %IntBroker.DefaultLocalNode(), MenuName.ROLE_MANAGER, %Market, Component.EP_APPR_MAIN, Page.EP_APPR_MAIN1, "U", &SrcgRecord);
&url = &url | "&SOURCE=MAP";
%Response.RedirectURL(&url);

The following example demonstrates how to generate the URL string to redirect the user to an iScript:

/* Example 3 */
Local string &iScriptName = "IScript_AppHP";
If &renderType = "HTML" Then
   &iScriptName = "IScript_AppHtml";
End-If;

&url = GenerateScriptContentURL(%Portal, %Node, Record.WEBLIB_PTPP_SC, Field.HOMEPAGE, "FieldFormula", &iScriptName);
%Response.RedirectURL(EncodeURL(&MyScriptURL));

Syntax

SetContentType(Type)

Description

This method sets the content type for this response. The parameter type takes a string value. This type may later be implicitly modified by the addition of properties such as the MIME charset property if the service finds it necessary and the appropriate property has not been set.

The content type defaults to "text/html" if it is not set.

Note: You can specify the content type as “text/html” to indicate that you do not want the input content to be modified or minified.

Syntax

SetHeader(name, value)

Description

This method sets a response header with the specified name and value. Both parameters take string values. If the field has already been set with a value, this new value overwrites the previous one.

Example

The PortalRegisteredURL response header identifies to the portal the registered URL of the current content, so that it can find the correct content reference to look at for the template.

You can override the value of the PortalRegisteredURL response header in a PIA Script or PIA Page by adding the header to the response yourself, like this:

%Response.SetHeader("PortalRegisteredURL", &myURL);

You can do this to register the content with additional parameters.

Syntax

UseSimpleURL({True | False})

Description

The UseSimpleURL method sets the response header that informs the portal that the current content uses relative simple URLs, and does not have to be proxied.

By default, all PeopleSoft Pure Internet Architecture content sets the header to true. You must to call this method to specify that your content does not use the simple URL format, and therefore does need to be proxied.

Parameters

Field or Control

Definition

True | False

Specify a Boolean value, either True or False, to indicate whether simple URLs are used.

Returns

None.

Syntax

Write(String)

Description

This method prints String to the HTTP output stream.

If you want the input content to be displayed as is, that is, you do not want the content to be minified, then you must set the type parameter to “text/html” in the SetContentType method.

You can use an HTML string from Application Designer HTML catalog with the Write method if you also use the GetHTMLText function, as follows:

%Response.Write(GetHTMLTEXT(HTML.MY_HTML));

You can also use an XML string. The following example takes a BiDocs structure that contains an XML response and puts that into a text string. After this is done, the %Response.Write function can send this as an XML response.

Local BIDocs &rootDoc; 
Local string &xmlString; 
 
&xmlString = %Response.GetContentBody(); 
&rootDoc = GetBIDoc(&xmlString); 
 
/* do processing */ 
 
&xmlString = &rootDoc.GenXMLString(); 
%Response.Write(&xmlString);

Syntax

WriteLine(String)

Description

This method adds a carriage control and line feed to the end of the string String, then prints the string to the HTTP output stream.

You can use an HTML string from Application Designer HTML catalog with the WriteLine method if you also use the GetHTMLText function, as follows:

%Response.WriteLine(GetHTMLTEXT(HTML.MY_HTML));