[aida] Aida application instance data
janko.mivsek at eranova.si
Tue Feb 5 22:44:29 CET 2008
Rob Rothwell wrote:
> Besides domain objects which are accessible by any user, any session (if
> security allows) you have the instances of an App, one per each session
> per domain object. You can put session specific (temporary!) data here.
> Temporary because this state is usually cleared, each night for
> instance. But you can use WebSession userValues or WebUser userValues
> for permanent session/user specific data.
> Maybe a more concrete example will help, because I am obviously missing
> Using Squeak, if I create domain object:
> Object subclass: #MyObject
> instanceVariableNames: 'textInput'
> classVariableNames: ''
> poolDictionaries: ''
> category: 'FMC-Model'
> And a WebApplication:
> WebApplication subclass: #MyObjectApp
> instanceVariableNames: ''
> classVariableNames: ''
> poolDictionaries: ''
> category: 'FMC-View'
> with a main view:
> e := WebElement new.
> e addTextH1: 'My Application'. e addBreak.
> e addText: self observee textInput. e addBreak.
> e addInputFieldAspect: #textInput for: self observee.
> self add: e.
> and create the site in a workspace with:
> SwazooAida startOn: 8890.
> obj := MyObject new.
> (AIDASite named: 'aidaOn8890') urlResolver defaultURL:
> '/myapplication.html' forObject: obj.
> And then open the site (http://localhost:8890/myapplication.html), I
> will see "nil" displayed on the screen the first time I enter the site
> right below the header. Once I enter "some text" into the input field,
> I will see "some text," and if I go to another computer and enter the
> site (http://mynetworkaddress:8890/myapplication.html), I will ALSO see
> "some text" displayed at the top of the screen.
That's completely right and expected Aida behavior, because from both
browsers you look at the same domain object. But see the further answer
> Furthermore, if I enter the site from the same computer in two different
> browsers and add "self inspect" at the top of MyObjectApp>>viewMain, I
> the app instance seems to be the same.
Do you mean different browser windows of the same browser (just FF for
instance) or two different browsers, like IE and FF? In first case it is
natural that you see just one session because by just opening a new
window you don't open a new session but reusing an existing one. In
later case you should have two separate sessions.
> Does it matter that I have "logged in" as admin in both cases?
> Where can I store data (and what methods do I use to access it) so that
> entering text on one computer does NOT affect what displays on another
You need to have different domain object for different sessions in that
case. As I described in previous mail you can use your App to hold that
domain object temporary or use WebSession or WebUser userValues for
permanent storage of such session/user specific domain objects.
> Sorry...there is something fundamental I don't understand yet.
It is very good that you raised that question because it seems that
many people have the same and it should be addressed in a tutorial or
maybe in FAQ.
> Session is shared only among App instances for different domain objects.
> But you have never more than one app instance for the same domain object
> per session. That's obvious if you know the rule: a new App instances
> for every new session, per domain object. So if you have say 10 domain
> objects and 10 session, you have up to 100 App objects, one for each
> session:domain object combination.
> So Sessions let different applications share objects?
Better said this enable apps to isolate their session specific state
from each others while observing the same domain object.
> Let we look at Aida tutorial: AddressBook with Addresses. That's a
> domain model with anAddressBook as root domain object. Is your question
> (translated to a tutorial case) how to add a new address to address
> No...it would be more like, how can two users have two DIFFERENT address
> books? Or, for something even more temporary (to use a common web
> analogy), how can two sessions have two different shopping carts?
Let's go with a shoping card analogy. You'll make a new ShopingCard and
register it in WebUser userValues until user checkout. At checkout
you'll add it to anOrders domain object. That's because you need to
store that shopping card permanently for a long time.
But if you don't care, you can store simply in an OrdersApp instvar
newOrder, for instance. That's because anORdersApp will be created for
each session separately, so you'll have and isolation of shoping card
Later case is preferred for short-living temporary state while former
for long-living ones , as I mentioned already.
Smalltalk Web Application Server
More information about the Aida