Home » General

Oracle ADF Basic: Making use of the ApplicationModule Session

Written By: Pascal Alma on May 3, 2008 No Comment

If you have to use a where-clause being based on session-scoped parameters in several viewobjects, it might be good to know you also have a session scope in Oracle's ADF BC Application Module. You get access to it by simply calling getSession() in your ApplicationModule. On the Session object which you then receive, you can perform a getUserData() which will give you a Hashtable object. In this object you can store the session parameters you like. This way you don't have to pass the parameters out of the Servlet Session object to the ApplicationModule for each call to a viewobject.
You might even overwrite the viewobject's executeQuery and check for a named bind variable to be available in the getUserdata() Hashtable. You will get something like this:

JAVA:
  1. @Override
  2.   public void executeQuery()
  3.   {
  4.     Variable[] vars = ensureVariableManager().getVariables();
  5.     for (Variable var: vars)
  6.     {
  7.       if (getNamedWhereClauseParam(var.getName()) == null ||
  8.           StringUtils.isEmpty(getNamedWhereClauseParam(var.getName()).toString()))
  9.       {
  10.         setNamedWhereClauseParam(var.getName(),
  11.                                  getApplicationModule().getSession().getUserData().get(var.getName()));
  12.       }
  13.     }
  14.     super.executeQuery();
  15.   }

You can put this method in your base ViewObject so all your viewobjects that extends this base class will then get the filtering functionality without any extra effort.
What we did was getting the necessary information from the database (based on the loggedIn userName) and store it in the hashtable.
We did this by overriding the prepareSession() of the Application Module. As long as you don't break the naming convention by giving the bindVariables in your viewobject exactly the same name as the corresponding attribute in your Userdata table this works very nice.

Tags:

Digg this!Add to del.icio.us!Stumble this!Add to Techorati!Share on Facebook!Seed Newsvine!Reddit!Add to Yahoo!

Comments are closed.

Copyright © 2009 Pascal’s Blog, All rights reserved.| Powered by WordPress