How to store instance of QueryModelBase during session?

Hello,

In LoginViewBean, after executing QueryModelBase.retrieve() to retrieve

Customer and verify Password, I would like to remember information about

current customer during a session.

Is it good idea to put this code into LoginViewBean?

"static final" - does it mean that all customers wil share the same

things?

I don't know the best way to store specific instance "currentCustomer"

during a session, so that different TiledViews and ViewBeans can access

it...

May be in ModuleServlet?

I want to use few instances of CustomersModelImpl with different

names...

I can put code in TiledView,

"setPrimaryModelClass(CustomersModel.class,true,true);", after

instantiation it will exist (I think) during a session...

Thanks,

Fuad

// I would like to store LoginViewBean.currentCustomer,

// and I will need additional instances of CustomersModelImpl for

another things

// !?

public static final CustomersModel currentCustomer =

(CustomersModel)getModel(CustomersModel.class);

// !?

// Verify Password:

String loginId = getDisplayFieldStringValue(CHILD_LOGIN);

String loginPassword =

getDisplayFieldStringValue(CHILD_PASSWORD);

currentCustomer.clearUserWhereCriteria();

currentCustomer.addUserWhereCriterion(currentCustomer.FIELD_CUSTOMERID,

loginId.toUpperCase());

currentCustomer.retrieve(null);

String customerId = currentCustomer.getCustomerId();

String customerPassword = currentCustomer.getPassword();

// Check the login name

if (loginId.equalsIgnoreCase(customerId) &&

loginPassword.equalsIgnoreCase(customerPassword)) {

// .............

}

[Non-text portions of this message have been removed]

[1903 byte] By [Guest] at [2007-11-25 9:35:02]
# 1

See below...

Fuad Efendi wrote:

>Craig,

>

>1. I have CustomersModelImpl class which I use in LoginViewBean for

>password verification. In future I will use the same Model for browsing

>Customers etc.

>As I understood, I should create two subclasses (with two

>subinterfaces?) for this two things, CurrentCustomerModelImpl and

>AllCustomersModelImpl...?

>

You only need the CustomersModelImpl. You do not need subclasses.

Remember, these models are request scope so a new instance is created

with each request, then destroyed at the end of the request (with very

little overhead, less than caching objects in a resource pool - reasons

which are outside this thread).

>

>

>2. In LoginViewBean,

>CustomersModel currentCustomer =

>(CustomersModel)getModel(CustomersModel.class);

>

>Then, I retrieve information about current customer,

>currentCustomer.clearUserWhereCriteria();

>currentCustomer.addUserWhereCriterion(xxx, zzz);

>currentCustomer.retrieve(null);

>

>How long will this be stored, can I "getModel" and have access to

>"current customer" somewhere outside of LoginViewBean? (during user's

>session)

>

The model is destroyed at the end of the request, so just get the info

you need from the model, and put it in the user's HTTP session. You can

put each piece of scalar data in a separate HTTP session attribute (HSA

for short), like this:

getSession().setAttribute("hsaFirstName", custModel.getValue("fname");

getSession().setAttribute("hsaLastName", custModel.getValue("lname");

getSession().setAttribute("hsaEmail", custModel.getValue("emailAddress");

etc.

or maybe you have a custom Customer class that you can stick in a HSA as a

whole complex object (as long as it is serializable), like this:

Customer cust = new Customer(...);

getSession().setAttribute("hsaCustRec", cust);

One other alternative would be to stick the whole model into session using a

unique "instance name", but you need to specify to store the model and look for

the model in session when you get the model:

getModel(CustomerModel.class, "customerRecord", true, true);

The first "true" param tells the model manager to look for this named model

instance in the HTTP Session first, then look in the current request scope,

then create a new one if one was not found in either place.

The second "true" param tells the model manager to store the model in session

at the end of the request.

Only store the entire model in session if you will need most of the data that

the model is holding. If you only need a couple of the fields of the customer

record, just session those values.

As for AllCustomer... there is no need to have a separate class for this. Just

get the model, execute it, possibly getting back a list of customers, use the

returned records for whatever purpose you like (display the list to the user

maybe), and it will not interfere with your sessioned customer data no matter

which technique above that you use.

Does this help?

craig

>

>

>Thanks a lot,

>

>Fuad

>

>--Original Message-

>From: Craig V. Conover [mailto:<a href="/group/SunONE-JATO/post?protectID=219212113009229091025149066024064239039 098031198039130252055210">craig.conover@s...</a>]

>Sent: Thursday, May 16, 2002 5:22 PM

>Subject: Re: [SunONE-JATO] How to store instance of QueryModelBase

>during session?

>

>

>Fuad,

>see below...

>

>Fuad Efendi wrote:

>

>>Hello,

>>

>>In LoginViewBean, after executing QueryModelBase.retrieve() to retrieve

>>Customer and verify Password, I would like to remember information

>>

>about

>

>>current customer during a session.

>>

>>Is it good idea to put this code into LoginViewBean?

>>"static final" - does it mean that all customers wil share the same

>>things?

>>

>No, remember that static resources are shared resources.

>

>>I don't know the best way to store specific instance "currentCustomer"

>>during a session, so that different TiledViews and ViewBeans can access

>>it...

>>May be in ModuleServlet?

>>I want to use few instances of CustomersModelImpl with different

>>names...

>>

>The HTTP session is for user specific data that is needed throughout the

>life fo the user's session.

>

>getRequestContext().getSession().setAttribute("attr-name", value);

>

>where value is any serializable object

>

>To get the HTTP session value:

>Object val = getRequestContext().getSession().getAttribute("attr-name");

>

>>I can put code in TiledView,

>>"setPrimaryModelClass(CustomersModel.class,true,true);", after

>>instantiation it will exist (I think) during a session...

>>

>You do not need to store your models in the HTTP session unless you are

>building the model up for a TX as some point. Even then you don't need

>to session the model, just create a custom class, like ShoppingCart, and

>add values to your model when you are ready to process the TX and

>persist to your DB (or wherever its being persisted).

>

>Also, be conservative on the amount of data you shove into the HTTP

>session. Some servlet containers perform poorly when user session get

>large. Use the same common sense as with any "data caching" mechanism.

>

>Hope that makes sense. If not, just ask some more.

>c

>

>>

>>Thanks,

>>

>>Fuad

>>

>>

>>

>>// I would like to store LoginViewBean.currentCustomer,

>>// and I will need additional instances of CustomersModelImpl for

>>another things

>>// !?

>> public static final CustomersModel currentCustomer =

>>(CustomersModel)getModel(CustomersModel.class);

>>// !?

>>

>>

>>// Verify Password:

>>

>> String loginId = getDisplayFieldStringValue(CHILD_LOGIN);

>> String loginPassword =

>>getDisplayFieldStringValue(CHILD_PASSWORD);

>>

>> currentCustomer.clearUserWhereCriteria();

>>

>>currentCustomer.addUserWhereCriterion(currentCustomer.FIELD_CUSTOMERID,

>>loginId.toUpperCase());

>>

>> currentCustomer.retrieve(null);

>>

>> String customerId = currentCustomer.getCustomerId();

>> String customerPassword = currentCustomer.getPassword();

>>

>> // Check the login name

>> if (loginId.equalsIgnoreCase(customerId) &&

>>loginPassword.equalsIgnoreCase(customerPassword)) {

>>// .............

>>}

>>

>>

>>

>>[Non-text portions of this message have been removed]

>>

>>

>>

>>To download the latest version of JATO, please visit:

>><a href="http://www.sun.com/software/download/developer/5102.html">http://www.s un.com/software/download/developer/5102.html</a>

>>

>>For more information about JATO, please visit:

>><a href="http://developer.iplanet.com/tech/appserver/framework/index.jsp">http: //developer.iplanet.com/tech/appserver/framework/index.jsp</a>

>>

>>

>>

>

>>

>

>

>

>

>

>

>

>To download the latest version of JATO, please visit:

><a href="http://www.sun.com/software/download/developer/5102.html">http://www.s un.com/software/download/developer/5102.html</a>

>

>For more information about JATO, please visit:

><a href="http://developer.iplanet.com/tech/appserver/framework/index.jsp">http: //developer.iplanet.com/tech/appserver/framework/index.jsp</a>

>

>

>

>

>

>

>[Non-text portions of this message have been removed]

>

>

>

>To download the latest version of JATO, please visit:

><a href="http://www.sun.com/software/download/developer/5102.html">http://www.s un.com/software/download/developer/5102.html</a>

>

>For more information about JATO, please visit:

><a href="http://developer.iplanet.com/tech/appserver/framework/index.jsp">http: //developer.iplanet.com/tech/appserver/framework/index.jsp</a>

>

>

>

>

Guest at 2007-7-1 18:36:41 > top of Java-index,Development Tools,Java Tools...