Search code examples
javascriptajaxxpagessession-variablesxpages-ssjs

How to store an IBM Notes Database Object variable in an XPage and Acess it later


I am trying to Store a (Javascript IBM Notes) Database Object in a variable onPageLoad so I can acess it later in the Code. I Tried setting viewScope and sessionScope variables but they always seem to return null.

onPageLoad:

var db_rooms: NotesDatabase = session.getDatabase(session.createName(doc_ProfileConfig.getItemValueString("ServerNA")).getCommon(), doc_ProfileConfig.getItemValueString("FilePathTX"));

viewScope.put("ResroomDb", db_rooms);

I use db_rooms to get data onPageLoad, so I know its a valid database object.

Now later when I try to get my Database again:

 var db:NotesDatabase = viewScope.get("ResroomDb");

Doing it this way will result in an Unable to load (status 500).

I tried both Session and ViewScope, is storing the Database Object in Application scope possible/a good idea, since its only a single page application?


Solution

  • Do not store any Domino-based object in a scope. You can't, because the handle (the pointer from the Java object to the underlying C++ object) gets recycled at the end of every request (page load, partial refresh etc).

    If you want to store anything, store the path / replica ID and retrieve the database via Session.getDatabase() again. Same for a document - store the UNID or NoteID and call the relevant Database method.