Skip to main content link. Accesskey S
  • Log In
  • Help
  • IBM Logo
  • IBM Notes and Domino Application Development wiki
  • All Wikis
  • All Forums
  • Home
  • Product Documentation
  • Community Articles
  • Learning Center
  • IBM Redbooks
Community Articles Product Documentation Learning Center IBM Redbooks This category Redbooks Wiki: Best Practices for Domino 8.0 Web Application Development Redbooks Wiki: Building Domino Web Applications using Domino 8.5.1 Redbooks Wiki: Creating Plugins for Lotus Notes, Sametime, and Symphony Redbooks Wiki: Lotus Domino Development Best Practices Custom Search Scope...
Search
Community Articles > API Documentation > XPages Extensibility API > How do you access the servlet objects, i.e. Request, response... etc.? What is the JSF context and what does it expose?
  • New Article
  • Share Show Menu▼
  • Subscribe Show Menu▼

About the Original Author

William Doran
Contribution Summary:
  • Articles authored: 2
  • Articles edited: 2
  • Comments Posted: 0

Recent articles by this author

XPages: How to log the XPages server runtime environment?

This article outlines the steps required to understand and implement logging of the XPages runtime environment on the Domino Server. We use the Java Logging API to take a look under the hood of ...

Accessing Servlet objects in XPages using the FacesContext object

The Java Server Faces (JSF 1.1) framework uses a FacesContext object to store all the contextual information related to a single incoming request from a client , and all the information needed to ...

Community articleHow do you access the servlet objects, i.e. Request, response... etc.? What is the JSF context and what does it expose?

Added by William Doran | Edited by IBM contributor Thomas Gumz on October 9, 2008 | Version 12
expanded Abstract
collapsed Abstract
No abstract provided.
Tags: jsf, faces context, context, external context
Introduction:
The Java Server Faces (JSF 1.1) framework (http://java.sun.com/javaee/javaserverfaces/1.1/docs/api/index.html) uses a FacesContext object to store all the contextual information related to a single incoming request from a client , and all the information needed to create a response to send back to the client. Stored messages, beans, renderkits and repsonseWriters are all examples of this form of information, which can then be used by the JSF framework to manage a GUI component's state for the duration of the request processing life-cycle.

External Context:

One of the more important pieces of information stored in the FacesContext is the  ExternalContext which is a wrapper that provides access to the webcontainer context and it is transparent to how the underlying server is implemented, i.e. servlet or a portlet. The ExternalContext can be used to access information about the request, such as the request header, cookies, locale, request parameters, session information, file and resource paths, and the application environment context. The application environment context can further be used to find information about the servlet/portlet running the application.
Each of the methods published in the APIs for FacesContext and ExternalContext (
http://java.sun.com/javaee/javaserverfaces/1.1/docs/api/javax/faces/context/package-summary.html) can be accessed by the global JavaScript objects made available to Xpages developers. For example, add the following lines of code your JavaScript to access the request object and information about the request using the facesContext global object :

 
var externalContext = facesContext.getExternalContext();
var request = externalContext.getRequest(); \\this is a HttpServletRequest
var serverName = request.getServerName();
var cookie = request.getHeader(“Cookie”);


Further examples:

Examples of how to use the facesContext global object can also be found by opening the "xpCGIVariables" JavaScript library in the Domino 8.5 discussion8.ntf template.
In Domio Designer, select File -> Application -> Open -> your_server_name -> discussion8.ntf. In the navigator window, expand the following menu elements: Code -> Script Libraries and open the library xpCGIVariables. For further details of how to use the JavaScript global objects see the articles on "Global Objects" and "JavaScript libraries in the Xpages engine",.

Sample Code:

/*
This server side script library implements a class named "CGIVariables" which allows for easy access
to most CGI variables in XPages via javascript.

For example, to dump the remote users name, IP address and browser string to the server console, use:
var cgi = new CGIVariables();
print ("Username: " + cgi.REMOTE_USER);
print ("Address : " + cgi.REMOTE_ADDR);
print ("Browser : " + cgi.HTTP_USER_AGENT);

Written July 2008 by Thomas Gumz, IBM.
*/

function CGIVariables() {
 
setup our object by getting refs to the request and servlet objects
try {
this.request = facesContext.getExternalContext().getRequest();
this.servlet = facesContext.getExternalContext().getContext();
} catch(e) {
print (e.message);
}
 
this.prototype.AUTH_TYPE = this.request.getAuthType();
this.prototype.CONTENT_LENGTH = this.request.getContentLength();
this.prototype.CONTENT_TYPE = this.request.getContentType();
this.prototype.CONTEXT_PATH = this.request.getContextPath();
this.prototype.GATEWATY_INTERFACE = "CGI/1.1";
this.prototype.HTTPS = this.request.isSecure() ? "ON" : "OFF";
this.prototype.PATH_INFO = this.request.getPathInfo();
this.prototype.PATH_TRANSLATED = this.request.getPathTranslated();
this.prototype.QUERY_STRING = this.request.getQueryString();
this.prototype.REMOTE_ADDR = this.request.getRemoteAddr();
this.prototype.REMOTE_HOST = this.request.getRemoteHost();
this.prototype.REMOTE_USER = this.request.getRemoteUser();
this.prototype.REQUEST_METHOD = this.request.getMethod();
this.prototype.REQUEST_SCHEME = this.request.getScheme();
this.prototype.REQUEST_URI = this.request.getRequestURI();
this.prototype.SCRIPT_NAME = this.request.getServletPath();
this.prototype.SERVER_NAME = this.request.getServerName();
this.prototype.SERVER_PORT = this.request.getServerPort();
this.prototype.SERVER_PROTOCOL = this.request.getProtocol();
this.prototype.SERVER_SOFTWARE = this.servlet.getServerInfo();
 
these are not really CGI variables, but useful, so lets just add them for convenience
this.prototype.HTTP_ACCEPT = this.request.getHeader("Accept");
this.prototype.HTTP_ACCEPT_ENCODING = this.request.getHeader("Accept-Encoding");
this.prototype.HTTP_ACCEPT_LANGUAGE = this.request.getHeader("Accept-Language");
this.prototype.HTTP_CONNECTION = this.request.getHeader("Connection");
this.prototype.HTTP_COOKIE = this.request.getHeader("Cookie");
this.prototype.HTTP_HOST = this.request.getHeader("Host");
this.prototype.HTTP_REFERER = this.request.getHeader("Referer");
this.prototype.HTTP_USER_AGENT = this.request.getHeader("User-Agent");
}
expanded Attachments (0)
collapsed Attachments (0)
expanded Versions (22)
collapsed Versions (22)
Version Comparison     
VersionDateChanged by              Summary of changes
29Nov 2, 2009 6:23:11 PMDeanna Drschiwiski  IBM contributor
28Oct 16, 2008 8:42:45 AMMaire Kehoe  IBM contributor
27Oct 10, 2008 9:18:27 AMWilliam Doran  IBM contributor
26Oct 10, 2008 9:15:48 AMWilliam Doran  IBM contributor
25Oct 10, 2008 6:09:25 AMWilliam Doran  IBM contributor
24Oct 10, 2008 6:04:24 AMWilliam Doran  IBM contributor
23Oct 10, 2008 6:01:20 AMWilliam Doran  IBM contributor
22Oct 9, 2008 9:00:16 PMThomas Gumz  IBM contributor
21Oct 9, 2008 8:47:42 PMThomas Gumz  IBM contributor
20Oct 9, 2008 8:47:08 PMThomas Gumz  IBM contributor
19Oct 9, 2008 8:46:24 PMThomas Gumz  IBM contributor
18Oct 9, 2008 8:43:35 PMThomas Gumz  IBM contributor
17Oct 9, 2008 8:40:51 PMThomas Gumz  IBM contributor
16Oct 9, 2008 8:39:40 PMThomas Gumz  IBM contributor
15Oct 9, 2008 5:23:38 PMThomas Gumz  IBM contributor
14Oct 9, 2008 5:19:06 PMThomas Gumz  IBM contributor
13Oct 9, 2008 5:16:55 PMThomas Gumz  IBM contributor
This version (12)Oct 9, 2008 5:02:27 PMThomas Gumz  IBM contributor
11Oct 9, 2008 5:01:00 PMThomas Gumz  IBM contributor
10Oct 9, 2008 11:16:35 AMWilliam Doran  IBM contributor
9Oct 9, 2008 11:15:56 AMWilliam Doran  IBM contributor
7Oct 9, 2008 10:48:50 AMWilliam Doran  IBM contributor
Copy and paste this wiki markup to link to this article from another article in this wiki.
Go ElsewhereStay ConnectedHelpAbout
  • IBM Collaboration Solutions wikis
  • IBM developerWorks
  • IBM Software support
  • Twitter LinkIBMSocialBizUX on Twitter
  • FacebookIBMSocialBizUX on Facebook
  • ForumsLotus product forums
  • BlogsIBM Social Business UX blog
  • Community LinkIBM Collaboration Solutions
  • Wiki Help
  • Forgot user name/password
  • Wiki design feedback
  • Content feedback
  • About the wiki
  • About IBM
  • Privacy
  • Accessibility
  • IBM Terms of use
  • Wiki terms of use