Session Handling in JATO
I am converting an application in ND5.0 to J2EE.
I have started working on this very recently.
I am looking for elaborate explanations on certain gray areas
My immediate concern using the JATO classes is "How do I store information
in the session"
The getRequestContext,getSession methods in ViewBean is returning null
Would appreciate if you could share your thoughts on "how to proceed" with
session management (Storing/Retrieving objects in session).
I am not clear on the Model classes.I plan to customize the model class per
the application needs and store it in the session...
For example, say there are 5 fields in the JSP
(Textbox1,Textbox2,Textbox3,Textbox4,Textbox5)
How about having 5 String attributes in the Model Class with Business
methods to Insert/Update the database
Would really appreciate more responses in this regard
Thanks,
Gajendran
[987 byte] By [
Guest] at [2007-11-25 9:30:50]

Stevens,
Thanks a lot for your reply.This has helped me a lot in understanding and
implementing the Session handling.One thing I struggled to fix was adding
the UserData.class in ModelTypeMapImpl.java
I am starting to admire JATO and I look forward to explore more into this.
Here comes my further questions on JATO....
Assume I have created a UserData (extending SessionModel) with two
parameters userId and passWord.
I want to write a method getDetails(),setDetails() which will fetch
details, update details from/to database respectively.
How do I go about this?Sample Code ..
Most of the business logic in ND5.0 is commented out in JATO (migrated
code).The commented code is appearing in the ViewBeans.
Enlighten me on the approach to rewrite the business logic. We basically
have little Functional Knowledge of the application written in ND5.0 -
Bearing this in mind, what is the cost-effective way to migrate the
business logic in JATO
Thanks,
Gajendran.
"Matthew Stevens"
Subject: RE: [iPlanet-JATO]
Session Handling
08/08/01 09:10 PM in JATO
Please respond to
iPlanet-JATO
Gajendran,
Which app server are you using when you have null reference returned for
HttpSession? This should not happen because the JATO base implementation
class for the Module Servlet (ApplicationServletBase) will automatically
force the creation of HttpSession in the container; this is required to
support the Session events.
Just to be clear (refer to the Java Docs for JATO) the API for accessing
the
HttpSession is
HttpSession sess = <RequestContext>.getRequest().getSession();
sess.setAttribute("XXXX",o);
. . .
There are rules defined in the latest Regular Expression Tool rules which
map NetD User Session APIs to HttpSession APIs. You can essential rely on
this. There are rules which is most cases assist you fixing the CSpValue
aspects of User Session expressions as well.
I highly recommend that you assemble your common Session attributes (NetDyn
User Session Objects) and encapsulate them in a java.model.SessionModel.
This model implements the <Model>.getValue() and <Model>.setValue() using
retrieval and storage from HttpSession automatically. In other words,
SessionModel is a proxy to HttpSession via a JATO Model API.
For a clean implementation, you can derive a specialized SessionModel. For
instance, it is fairly common to store a number of Login or User related
attributes in session. You can create a class UserData which derives from
SessionModel, add your own purposeful accessors (setters and getters), and
reap the benefits of having this session data available via Model APIs.
Here is an example below
public class UserData extends SessionModel
{
. . .
protected static final String LOGIN_TIME
= "USERDATA_LOGIN_TIME";
public void initializeLoginTime()
{
setValue(LOGIN_TIME, new Long((new Date()).getTime())
}
public long getLoginTime()
{
TypeConverter.asLong(getValue(LOGIN_TIME));
}
public long getLoginTimeAsString()
{
TypeConverter.asString(new
Date(TypeConverter.asLong(getValue(LOGIN_TIME))));
}
}
UserData x =
(UserData)<RequestContext>.getModelManager().getModel(UserData.class);
x.initializeLoginTime();
With respect to business objects, the JATO Models are in fact intended for
this purpose (e.g. Business Delegate pattern). JATO Models can
automatically be stored in the HttpSession via the ModelManager support for
retrieving and storing Models in session (see the getModel() APIs). If a
Model is backed by a database (e.g. QueryModel or UIFFunctionModel) then
you
need to decide whether the data is too expensive to be pulled out of the
backing store on each request. There is a tradeoff (especially in data
integrity) on whether Models should be cached in the session in addition
its
primary storage in the database. Here is an example. For one NetDynamics
customer which had a PAC based Function Data Object which accessed consumer
Credit Reports from a mainframe, the cost in both RPC latency and local CPU
time for post-processing the results was far greater than the cost of
storing the 1-2K of credit report data in the HttpSession. For this
customer, it was very simple to leverage the ModelManager automatic feature
for storing and retrieving (serializable) Models from HttpSession.
public Model getModel(java.lang.Class modelClass,
java.lang.String instanceName,
boolean lookInSession,
boolean storeInSession)
Model credit_report =
getModel(ConsumerCreditReportModel.class,some_name,true,true);
In this way, the first access to getModel returned an empty/default
implementation class for the ConsumerCreditReportModel. Execution of this
getModel() call on subsequent requests retrieved the Model out of
HttpSession.
let us know if this answers your question,
matt
> --Original Message--
> From: <a href="/group/SunONE-JATO/post?protectID=123166177056078154218098066036192063041 102166009043241114211116056004136218164200193244096076095219">gajendran.gopin athan@i...</a>
> Sent: Wednesday, August 08, 2001 7:42 AM
> Subject: [iPlanet-JATO] Session Handling in JATO
>
>
> I am converting an application in ND5.0 to J2EE.
> I have started working on this very recently.
> I am looking for elaborate explanations on certain gray areas
>
> My immediate concern using the JATO classes is "How do I store
information
> in the session"
> The getRequestContext,getSession methods in ViewBean is returning null
>
> Would appreciate if you could share your thoughts on "how to proceed"
with
> session management (Storing/Retrieving objects in session).
>
> I am not clear on the Model classes.I plan to customize the model
> class per
> the application needs and store it in the session...
> For example, say there are 5 fields in the JSP
> (Textbox1,Textbox2,Textbox3,Textbox4,Textbox5)
>
> How about having 5 String attributes in the Model Class with Business
> methods to Insert/Update the database
>
> Would really appreciate more responses in this regard
>
> Thanks,
> Gajendran
<a href="/group/SunONE-JATO/post?protectID=210083235237078198050118178206047166215 146166214017110250006230056039126077176105140127082088124241215002153">iPlane t-JATO-unsubscribe@egroups.com</a>
Guest at 2007-7-1 18:23:27 >

Hi Gajendran--
> My immediate concern using the JATO classes is "How do I store information
> in the session"
> The getRequestContext,getSession methods in ViewBean is returning null
Why you are receiving null from these methods inside your J2EE container, I
don't understand. This basically shouldn't be possible. Which container
are you using to test your application?
Regardless, JATO has no notion of session itself--it merely provides access
to the container's HttpSession. The only difference in JATO versus straight
servlets is that the servlet request and response objects are wrapped in the
JATO RequestContext, which is available anywhere in your JATO application.
Once you have the request context, you can retrieve the servlet request
object, and from there, retrieve the HttpSession. See the J2EE
documentation for information on that class's API.
> Would appreciate if you could share your thoughts on "how to proceed" with
> session management (Storing/Retrieving objects in session).
It's no different that you would do in a servlet: you use the HttpSession's
getAttribute()/setAttribute() methods to get values from and set values to
the session. The determination of the right level of courseness for your
sessioned objects depends on your needs. Generally, it is easiest to
collect several values that need to be persisted across requests in a single
sessionable object, rather than store the values separately.
> I am not clear on the Model classes.I plan to customize the model class
per
> the application needs and store it in the session...
> For example, say there are 5 fields in the JSP
> (Textbox1,Textbox2,Textbox3,Textbox4,Textbox5)
>
> How about having 5 String attributes in the Model Class with Business
> methods to Insert/Update the database
Any JATO Model that is Serializable can be stored in the session, just like
any other serializable object. There are also methods in the ModelManager
to help with this, as Matt Stevens has already mentioned.
As for the idea of using a model as a proxy for backend database access,
please see the SQL examples in the MigtoolboxSample application. JATO
defines several standard interfaces for models that are "executable",
meaning that in addition to having methods for storing and retrieving data,
they expose methods for performing bulk operations on that data, such as
retrieving it from a backend database. I'm speaking here about the
ExecutingModel interface and its descendents. These interfaces can be
implemented by any model that needs to do this sort of thing, and then will
integrate seamlessly with the rest of JATO. JATO also provides stock
implementations of models that use a JDBC datasource to store data. Please
see the jato.model.sql package.
Todd
Guest at 2007-7-1 18:23:27 >

Gajendran--
> Here comes my further questions on JATO....
> Assume I have created a UserData (extending SessionModel) with two
> parameters userId and passWord.
> I want to write a method getDetails(),setDetails() which will fetch
> details, update details from/to database respectively.
> How do I go about this?Sample Code ..
As I mentioned in my previous email, there are standard approaches in JATO
for this. But first, let me clarify something.
You have an object called UserData whose data you want to store in session.
You shouldn't derive this object from JATO's SessionModel class, because
SessionModel is merely an adaptation of the JATO Model interface to the J2EE
HttpSession interface. Instead, you should derive UserData from
DefaultModel. (You may want to change the name of your object to
"UserDataModel" to be consistent with JATO's naming convention.)
DefaultModel is a serializable class, so this means that you can simply
store the UserData object directly in the session as needed. There are also
methods in the ModelManager class that will help you store and retrieve a
Model from session.
Now, because this class implements the Model interface, you can bind it to
JATO display fields. Also, because the UserData class ISA Model, you can
have it implement one or more of the ExecutingModel interfaces, like
RetrievingModel and UpdatingModel. These interfaces give you standard
methods for the behavior you want to put in your getDetails()/setDetails()
method. Once you have these standard methods, you can then integrate the
UserData class with JATO WebActions, and have it automatically execute
during specific actions.
Finally, for an example of implementing a custom Model class, see the
BasicCustomModel.java and BasicCustomModelImpl.java classes in the JATO 1.1
sample application, available here:
<a href="ftp://ftp1.netscape.com/private/jato/1_1/JatoSample.war">ftp://ftp1.ne tscape.com/private/jato/1_1/JatoSample.war</a>
Todd
Guest at 2007-7-1 18:23:27 >
