Topic
  • 4 replies
  • Latest Post - ‏2012-12-06T21:10:51Z by SystemAdmin
dmelby
dmelby
131 Posts

Pinned topic Load session variables once in portlet

‏2012-12-06T19:27:51Z |
The portlet I'm building needs to have a couple of session variables present which I will be using in various parts of the portlet. The variables do not change and only need to be intialized at startup. A java method will be called to load up the variables. What's the best approach? Does anyone have a model or example which demonstrates this process?
Updated on 2012-12-06T21:10:51Z at 2012-12-06T21:10:51Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    9029 Posts

    Re: Load session variables once in portlet

    ‏2012-12-06T20:42:33Z  
    Thinking out loud:

    Event Handler has a built in event for onWebAppLoad, which happens once. Perhaps catch this event and load your variable.
    --Sam
    The postings on this site are my own and do not necessarily represent the positions, strategies, or opinions of IBM.
  • SystemAdmin
    SystemAdmin
    9029 Posts

    Re: Load session variables once in portlet

    ‏2012-12-06T20:44:31Z  
    Rereading your post, I have questions:

    What do you mean by startup? Do you mean when the user logs in? Or is the variable the same for all users or user-specific?
    --SamThe postings on this site are my own and do not necessarily represent the positions, strategies, or opinions of IBM.
  • dmelby
    dmelby
    131 Posts

    Re: Load session variables once in portlet

    ‏2012-12-06T20:55:47Z  
    Rereading your post, I have questions:

    What do you mean by startup? Do you mean when the user logs in? Or is the variable the same for all users or user-specific?
    --SamThe postings on this site are my own and do not necessarily represent the positions, strategies, or opinions of IBM.
    That is a very good question! This is for a registration system, and I'm going out to the database to grab the current registration year for a conference in the spring. This won't change until after the conference. The second variable will be a portion of the user ID that they signed into Portal.
  • SystemAdmin
    SystemAdmin
    9029 Posts

    Re: Load session variables once in portlet

    ‏2012-12-06T21:10:51Z  
    • dmelby
    • ‏2012-12-06T20:55:47Z
    That is a very good question! This is for a registration system, and I'm going out to the database to grab the current registration year for a conference in the spring. This won't change until after the conference. The second variable will be a portion of the user ID that they signed into Portal.
    The first variable is cross-user. I wouldn't create an instance for every session. Consider Shared Variable. OnWebAppLoad event can set it. Alternatively, along with a SQL Call builder, you could create a getRegistrationYear() Service Operation in a provider model and enable caching in the Service Operation builder, which would enable cross-user caching of the variable.

    The second variable sounds user-specific. If you need it for the entire session, just use a Variable builder and set it. There are portal api's to get the user, such as PUMA. If you don't need it for the entire session, perhaps limit its scope to request-scope. See the Discardable Variable builder.
    --Sam
    The postings on this site are my own and do not necessarily represent the positions, strategies, or opinions of IBM.