For example, from Scout Form execStore() method, right before executing any server services, i like to get the HttpSession and eventually get custom data from its attributes store.
How can I access the request HttpSession from Scout client side code?
110 views Asked by Johny Kwan At
1
As mentioned in the comments, Eclipse Scout separates the UI Layer (the HTML rendering - or the Swing client in older versions) from the client model. And while the UI Layer knows about the HttpSession, the client model, in which your form lives, does not.
You can however put the relevant attributes on the ServerSession (backend) and synchronize them to the ClientSession (model) or vice versa - depending on where your attributes come from.
This sketch should get you started:
extends AbstractServerSession) add a getter and setter.org.eclipse.scout.rt.server.context.HttpServerRunContextProducer. Create a subclass of this class in your .server-part, and add the@Replaceannotation. Your best place to implement it is likely in the methodpublic IServerSession getOrCreateScoutSession(HttpServletRequest req, ServerRunContext serverRunContextForSessionStart, String scoutSessionId)org.eclipse.scout.rt.ui.html.UiSession.createAndStartClientSession(Locale, UserAgent, Map<String, String>)on how the ClientSession is created and if you can access your data at this location.