Via client side javascript I set a sessionscope variable via an jsonRpcService.
Via server side javascript I read the sessionscope variable and do something with it.
I notice however that sometimes the ssjs reads the sessionscope variable as null but if I check the scope variable via the debug toolbar the scope variable contains values.
I assume that changes via the rcp service have not yet become available for the server code.
Is there a way to update the scope variables from serverside without doing a full page refresh or from client side perform a page refresh so values are transferred from browser side to server side?
Related
I have an extension that need to wirte something in localStorage and clean (or set a special value) when user close the browser.
This link showing that there is no way to detect when the browser is closed.
So any suggestion?
If you're using a persistent background page, use sessionStorage instead of localStorage to save variables.
If you're using an event page, then you need to maintain some kind of session identifier, and prefix your value or key with this identifier. This identifier can be stored in localStorage and must be refreshed during the chrome.runtime.onStartup and chrome.runtime.onInstalled events.
A. What is the actual lifetime of an application scope variable in xpages?
B. how can i remove/reset it if necessary?
(I can't find anything like "re-deploy" or "start-stop application", so do i have to restart the webserver,do it with code, just re-save my application from designer or anything else...?)
A. It varies. You can set an explicit timeout in the XSP Properties (surfaced in Designer 9 as a design element under the Application Configuration category; in 8.5.x you'll need to navigate to WebContent/WEB-INF/xsp.properties via Package Explorer). Otherwise, it times out when Domino thinks it "should". This is based on application usage, so the more heavily the app is used, the less likely the scope will ever expire unless the HTTP task -- or Domino itself -- is restarted.
B. To destroy the entire scope, restart HTTP (or restart Domino entirely). NOTE: this is not
Tell HTTP Restart
...which only reloads certain portions of the task, and does not reload the JVM. You need to actually restart the task:
Tell HTTP Quit
Load HTTP
OR
Restart Task HTTP
After the task restarts, a fresh application scope will be instantiated the next time the application is accessed.
You can also selectively clean the scope. Each of the scopes in XPages (request / view / session / application) is an instance of a Java Map, so each supports all of the methods defined in that interface.
I would recommend only removing specific items, e.g.:
applicationScope.remove("myBean");
If you clear the entire scope without actually destroying the scope itself (see above), it can cause unpredictable behavior, because the platform also stores its own information in the application scope (this applies to the other scopes as well). You should only remove scope entries that you added.
As the Name application scope variable already tells you its lifetime is as long as the application is running if defined in the xsp.properties if you defined nothing the standard duration is 30 minutes. or Or from IBM:
The applicationScope duration is the WebModule duration. A web module is started when the first request comes in, and is eventually discarded after a period of inactivity, the default being 30 minutes. Every user of the application can access these variables once they are created, so there is no privacy with these variables. The applicationScope should only be used for data that must be shared among many XPages.
If you develope using application scope vars you can reset them by clearing your Application in designer go to: Projekt => clear...
or if this does not help try following code from Tommy Valand:
function clearMap( map:Map ){
// Get iterator for the keys
var iterator = map.keySet().iterator();
// Remove all items
while( iterator.hasNext() ){
map.remove( iterator.next() );
}
}
This will allow you to reset the application scope durring runtime, verry usefull for debugging and testing.
I believe that refreshing the design also clears application scope variables....
In a XPages application, I want to store some (confidental) information in the applicationScope to make it accessible for all users. However, the ACL of the application is configured such that anonymous users are allowed to read public documents. Still, I do not want them to have access to the applicationScope. Is it possible for an anonymous user to access/read the applicationScope?
All the scope variables (including applicationScope) are memory contexts. The term "scope", in this case, refers to how broadly each can be accessed.
requestScope can be accessed by any code executing within the current page for the duration of a single HTTP request, at which point the object is destroyed. Any other pages, and any subsequent requests against the same page instance, have their own separate requestScope.
viewScope can be accessed by any code executing within the current page for the life of that page instance. Other pages -- including those accessed by the same user -- have their own viewScope. Similarly, if the user navigates to another page, and then navigates back to the previous page, that's a new viewScope because it's a new instance of the page.
sessionScope can be accessed by any code executing within any page during a single HTTP session. This is tied to session cookies in the browser, not to authentication. So if an anonymous user later logs in, it's still the same sessionScope. If they later log out, they still have the same sessionScope until they close their browser or the application clears out the storage.
applicationScope can be accessed by any code executing within any page within the current application. This is what allows it to be shared across users: If User1 is accessing app1.nsf/page1.xsp on one computer while User2 is accessing the same page -- or a different page -- within the same NSF, they have the same applicationScope -- the variable refers to precisely the same in-memory object for both users -- so any data stored via code executed by one user can be retrieved via code executed by another user until the application clears out the storage.
BUT, if User1 is accessing any page in app1.nsf and User2 (or Anonymous) is accessing any page in app2.nsf, the variable applicationScope refers to different in-memory objects for each user, because they are accessing different applications, even if there is code in either app that accesses on-disk data in the other app. The in-memory object that the applicationScope variable refers to is different in each NSF, no matter where any on-disk data it may access or create happens to be stored.
So you (and anyone else writing code in the same NSF) still need to be diligent about how you structure your logic to avoid storing sensitive information in applicationScope and then exposing it to users who shouldn't have access to it, but you don't need to worry about code executed from other applications accessing the same memory scope. Code can only read the data you store in your applicationScope if that code is executed from the same NSF.
A user can only read values from applicationScope and other scoped variables if you expose the value through visible controls on an XPage. So if you do not expose the values, then a user (anonymous or not) can not see the value.
I'm new to JSF and I was doing some research about Scopes and Http session lifecycles, but one thing was not clear to me.
I know that is possible to store variables using sessionMap from ExternalContext, and it used to work very fine for what I needed. I also know that when the session is invalidated all the data stored on the map is lost.
However, what I don't know is: when the page is refreshed the session is invalidated?
My problem appeared when I had to put a download request on one of the buttons from my web application. Apparently download requests cannot be made via Ajax, so the entire page have to be refreshed. The download proceed normaly, but after that, all the data stored on the map is gone, including all the managed beans. The user data itself is not that important as I can store it and then put it again on the new session map. But what about the managed beans? How should I proceed?
Assuming that it's not the webbrowser who misbehaved, this can only happen if the server side code is actually by itself invalidating the session by calling ExternalContext#invalidateSession() or HttpSession#invalidate().
If you can't seem to nail it down, then create a HttpSessionListener and put a debug breakpoint on sessionDestroyed() method and investigate the call stack who initiated it and why.
In my application I have created some locking / unlocking functionality based on the current page that the user is viewing. A user can view a page and will acquire a lock which is stored in my database, when they navigate away the lock is released and the database is updated.
I am trying to handle the situation when the user closes the browser window without logging out. They will still be holding the lock and I need that to be released and a database call needs to occur.
Is there a way to handle this in a JSF application using Spring or something else?
I know the javascript function onbeforeunload but I need to call a java method that will enable me to update the database.
The unload and beforeunload events aren't going to help you here since it's not by the specification guaranteed that any ajax request which is fired within those events is ever going to successfully hit the server. More than often, this won't.
The most reliable way is to keep the server side session lifetime very short, e.g. 1 minute and introduce an ajax poller on the page which polls within the same session to the server every minute (minus a few seconds) until the user is been inactive for more than the actual maximum session timeout. The user activity can be tested by listening on JavaScript keyboard (keyup) and mouse (click) events.
I am currently working on a two window application and needed to detect when a window is closed.
My JSF application uses ICEfaces. It provides an #WindowDisposed annotation for ViewScoped beans. With this annotation, the ViewScoped bean's #PreDestroy method will be called when the window is closed.
I have included an h:inputHidden tag in my page bound to the viewScoped bean and this works in terms of detecting the window closing and executing server side code.