i have gwt mvp application using activities , places. inspired mauro bertapelle's sample (in this thread), apparently based on of thomas broyer's work.
here's problem: have loginactivity make rpc call, successful login, returns user. user has role (e.g., admin, regular user, guest). several views , activities, including navigatorview, depend on role show or do. how user instance other activities?
i not have clientfactory; injection (gin) used instantiating views in activityproviders provide activities/presenters, , activityproviders injected activitymapper. may reduce gin question: how user reference it's needed? seems similar this question global references in mvp.
consider me gin newbie, first attempt @ using it. i'm guessing there "gin way" make happen, don't know gin enough know best way (if gin should used @ all).
much thanks.
edit 1: despite best efforts searching similar question, found this question pretty identical mine (is algorithm finding "related" links better search?). i'm thinking gin answer david on right track.
i don't think eventbus solution possible. i'm following google guidelines involve instantiating activity @ every place change, single event not suffice.
i had similar requirements on recent project.
when reply login (or logout) rpc send custom authenticationevent on eventbus. activities interested in listen event. authenticationevent has reference appuser object null if user logged out. appuser contains necessary data (privileges, groups, etc..) activities can inspect , act upon it.
about global references: can have class static methods providing data need. class internally holds singleton references needed instances. in example have static method apputils.getcurrentuser(). internally holds reference appuser , listens authenticationevent set/reset field.
as side note: don't rely on client side enforce access restrictions - should separate rpc servlets 2 groups: public , private. public can accessed (this login/logout rpc , other public info rpc), while private rpc requires user authenticated. access restrictions can set per path/servlet: http://code.google.com/appengine/docs/java/config/webxml.html#security_and_authentication
update:
as noted, class static methods not advisable in setup, because not replaceable , prevents testing (which whole point of using gin).
the solution inject utility class holding globals (apputils) activities need globals. apputils should declared singleton in gin configuration 1 instance enough whole app.
to use
provider
or not question if want delay initialization of dependencies (apputil dependency). since apputils singleton whole app makes no sense have lazy initialized.sometimes have situation have multiple activities shown on screen (in case menubar , infobar). in case, when user logs in need way notify them of change. use eventbus.
Comments
Post a Comment