Skip to main content link. Accesskey S
  • Help
  • HCL Logo
  • HCL Notes and Domino Application Development wiki
  • THIS WIKI IS READ-ONLY. Individual names altered for privacy purposes.
  • HCL Forums and Blogs
  • Home
  • Product Documentation
  • Community Articles
  • Learning Center
  • API Documentation
Search
Community Articles > Designing Applications > Designing XPage Applications > Do's and Do Not's for XPages Scoped Variables
  • Share Show Menu▼
  • Subscribe Show Menu▼

Recent articles by this author

Do's and Do Not's for XPages Scoped Variables

Scoped variables should be used in caution in XPages applications. We will mention about some usages in scope variables that are not advised.

Authorizing Notes Client User to Web Applications via Ltpa Tokens

Normally, if you are using hybrid application scheme (that is your users are accessing both notes apps and web apps), they need to login to Domino Web server each time they try accessing a web application. Some companies have problems with password syncronization between Notes password and ...
Community articleDo's and Do Not's for XPages Scoped Variables
Added by ~Ben Kifanamaroni | Edited by ~Ben Kifanamaroni on September 11, 2011 | Version 3
  • Actions Show Menu▼
expanded Abstract
collapsed Abstract
Scoped variables should be used in caution in XPages applications. We will mention about some usages in scope variables that are not advised.
Tags: xpages, SSJS, Scope Variables
ShowTable of Contents
HideTable of Contents
  • 1 Scoped Variables
  • 2 Storage in Scoped variables
    • 2.1 Notes Objects
    • 2.2 Serialization Issue
  • 3 Credits
 

Scoped Variables

In XPages development, there are several layers of scoped variables which are some sort of implementation of Java hashmaps to store different objects.  There are five levels of scopes in XPages. Refer to Scoped Variable in XPages article for more information.
 

Storage in Scoped variables

Normally, Java Hashmaps provide no restriction storing objects. You can always store any object in a scoped variable: 
 

sessionScope.name=session.createName(session.getUserName());
 
Although it is legitimate, the storage of some objects are not good practices. Let's explore some aspects:

Notes Objects

 
Notes objects like NotesDocument, NotesView, NotesDatabase, etc. are not based on SSJS or Java. At the bottom level, they are based on C-equivalents and they don't have automated garbage collection. So storing them into hashmaps will have toxic effects in the JSF cycles and memory management. Read Tim's commentexternal link for more explanation.
 
You have to use primitive information about objects. For instance, if you want to store a profile document on applicationScope, the best practice will be using its universal ID. The same will be applied for view name instead of NotesView, database file path instead of NotesDatabase, etc.

Serialization Issue

 
First, we will explain the Serializationexternal link concept: Serialization is the ability to convert some data structure to a type that can be stored to a file/memory buffer and/or transmitted over a stream. 
 
When XSP server serves a page, it constructs a 'in-memory' tree structure. This tree-structure, we can call it as the page, contains many objects like div elements, viewScope, etc. The page is being used to operate between states and changes. In 8.5.1, this page was being stored in memory. If hundreds of users requesting the same page. Memory will be filled with hundred 'page's in memory for each request. That's why XPages consumes so much memory but it feels very fast after the initial launch. 

However, XPages team creates an additional method to increase scalability. After 8.5.2, XSP server has the ability to store those pages in disk. It decreases the performance because of the increase in disk activity, but it improves the scalability which means you may serve more and more users with the same memory space. 

XSP server is using serialization to store the page into the disk. So if you have objects that are not serializable in your viewScope, it will fail writing these pages into the disk and throws the error: "java.io.NotSerializableException: 'some object type'".
 
The most common type of unserializable object is SSJS functions. You may use them in the requestScope but any objects that are not serializable should not be used in higher scope. viewScope will certainly fail depending on the configuration. Although the higher scopes seem safe currently, this would be changed in the future for reasons like clustering.  

Consider that 'Keep pages on disk' feature is the default option in newly created databases in 8.5.2. It can be changed under XPages tab in Application Properties page.
 
Image:Serialization, viewScope and Exploding XPage after Upgrade...
 
You may read more about this issue at the following blog topics:

XPages Gut Checkexternal link in Notes In 9external link (David Leedy)
Serialization, viewScope and Exploding XPage after Upgrade...external link in Lotus Notusexternal link (Serdar Basegmez)
 

Credits

 
Tim Tripconyexternal link and  David Leedyexternal link found and explained the problem in such detail.
 

  • Actions Show Menu▼


expanded Attachments (0)
collapsed Attachments (0)
Edit the article to add or modify attachments.
expanded Versions (3)
collapsed Versions (3)
Version Comparison     
VersionDateChanged by              Summary of changes
This version (3)Sep 11, 2011, 11:39:03 AM~Ben Kifanamaroni  
2Sep 11, 2011, 9:52:08 AM~Karl Quetjumitherikle  Minor change
1Sep 11, 2011, 9:45:05 AM~Karl Quetjumitherikle  
expanded Comments (0)
collapsed Comments (0)
Copy and paste this wiki markup to link to this article from another article in this wiki.
Go ElsewhereStay ConnectedAbout
  • HCL Software
  • HCL Digital Solutions community
  • HCL Software support
  • BlogsDigital Solutions blog
  • Community LinkHCL Software forums and blogs
  • About HCL
  • Privacy
  • Accessibility