0

I am running Xpages in XPiNC.

My usual pattern for an Xpages app is to have a xpHome.xsp page that is set to be the first page that is opened. In this I page I set any scope variables that are at the application level, then head to the "real" first page.

Now I have run into a problem. My current database will send out emails when a status changes, and this will include a doc link to the document, which points to the correct Xpage to open. However, because the user is not going through the home page, then my applicationScope vars are being set.

I thought I could fix this by setting a semaphore in the initApp function - the last thing it would do is to place a "Y" in an applicationScope.semaphore field. So when I open my Xpage the first thing it does is check for that, and if it is null, then I call the initApp function.

For some reason this is not working. But even so I would like to find the equivalent of the old database script "Initialize" event. Something I can call whenever the db is opened for the first time.

How do others handle this problem?

Bryan Schmiedeler
  • 2,977
  • 6
  • 35
  • 74
  • Please add the code for your check, as well as confirming if it's in a SSJS Script Library and where that's added. I have used the method of an initApp function setting a variable once complete for many years without problem. – Paul Stephen Withers Oct 13 '15 at 07:54

1 Answers1

7

Create a managed Java bean "app" which

  • works on application scope
  • sets all application parameters
  • offers all application parameters

Access the bean with app.xxx in EL or Javascript or call methods directly like app.getXxx() or app.doWhatEverYouWant() in JavaScript.

The bean "app" gets initalized automatically when one of the methods gets called first time.

You can find an example here for start or google for "XPages managed beans" for more Information.

Yes, you have to switch your current code partly to Java but it should be worth it in the long run.


If you want to or have to stay with JavaScript then initialize your application scope variables in a custom control which is included in every XPage like layout.xsp in beforePageLoad event.

Use an additional variable applicationScope.initialized. Check if applicationScope variables aren't initialized yet in JavaScript with

if (!applicationScope.initialized) { 
    ... initialize your applicationScope variables ...
    applicationScope.initialized = "yes";
}
Community
  • 1
  • 1
Knut Herrmann
  • 30,880
  • 4
  • 31
  • 67