Reputation: 15
I have an Xpage with a view within it that displays search results that are based on the values of 6 fields on the xpage (These values are assigned to sessionscope variables when they selected, which drives the view selection when the search button is hit). This all works well, but what I'd like to change is that the view is empty when the xpage is opened initially (before any values are set).
Apologies for the simple question, but I haven't touched notes since 2006 and its changed a fair bit since then.
Running 8.5.2.
Upvotes: 1
Views: 822
Reputation: 2807
Each bean is instantiated when the scope is "initiated". For sessionScope this when you first open the site. For viewScope it is when you first open the page (will survive partial refreshes). And variables in these scope are just maps (i.e. beans) in that scope.
So to set an initial value you could either use a real bean - and just add whatever code you need in its constructor.
Or, if you want to use SSJS, you can add the check when loading a page (e.g. in the beforePageLoad event). If you are working in sessionScope you should check if a value is already set - and if not --> set it. In viewScope you would just initiate the variable.
And a word on scopes. If at all possible you should always prefer the "shorter" timed scope for performance/scalability purposes. See a little more about using sessionScope in my article about tuning XPages :-)
/John
Upvotes: 1
Reputation: 30960
Use viewScope instead sessionScope.
viewScope variables exist for the duration of the current XPage in current browser tab. If you open another XPage or open current XPage in another tab the values of viewScope variables are gone. That is what you need in your case.
sessionScope variables last for the duration of a user session in a browser across all browser tabs. That's why your current search values are set as default in another browser tab.
Upvotes: 0