This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information

--Using SessionContext

Documents for the development of and with JVx.

--Using SessionContext

Postby Development@SIB » Sun Sep 12, 2010 10:23 am



This article is outdated - please use our new system at

https://doc.sibvisions.com




SessionContext is an object available only at the server that enables access to session information as well as certain objects related to a session during the handling of a client request.


Example

We have developed an application that reviews all existing messages in an e-mail account and displays the number of messages. The request is initiated at the client by clicking a button.

The call using a button is illustrated in Client Actions or Server Actions

The server action accesses the mail server; the required access data is obtained from the application configuration.

Sample code for the server action:

Code: Select all
   /**
    * Returns the number of mails from a preconfigured email account.
    * 
    * @return the number of mails
    */
   public int getEmailCount()
   {
      IConfiguration cfgSession = SessionContext.getCurrentSessionConfig();

      String sServer = cfgSession.getProperty("/application/email/server");
      String sPort = cfgSession.getProperty("/application/email/port");
      String sProtocol = cfgSession.getProperty("/application/email/protocol");
      String sUser = cfgSession.getProperty("/application/email/username");
      String sPwd = cfgSession.getProperty("/application/email/password");
      
      MailCheck mcheck = new MailCheck(sServer, sPort, sProtocol);
      
      return mcheck.getMails(sUser, sPwd).size();
   }   

Excerpt from the configuration file:

Code: Select all
  ...
  ...

  <email>
    <server>servername or ip</server>
    <port>110</port>
    <protocol>pop3</protocol>
    <username>username</username>
    <password>password</password>
  </email>
   
</application>


SessionContext Life Cycle

sessioncontext_lifecycle.png
sessioncontext_lifecycle.png (10.7 KiB) Viewed 9577 times


Additional examples

SessionContext can also be used for the following:

  • Access session properties (e.g. application name, username, client properties)
  • Request the name of the current action
  • Access the server configuration
  • Use of the direct server connection
  • Add or remove objects related to a call
User avatar
Development@SIB
 
Posts: 325
Joined: Mon Sep 28, 2009 1:54 pm

Return to Documentation