0

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.

  • 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. Can you describe what problem you are trying to solve? – Patrick Jul 17 '20 at 10:42
  • Thanks, that's explained why i can't get a hold of HttpSession from client area. I am trying to have a custom data attached to user that logged in, currently i load these data into HttpSession attrs via custom authorization code ( UI layer ). – Johny Kwan Jul 18 '20 at 11:11
  • I'm looking for a better way to have these session data available before service call to server. – Johny Kwan Jul 18 '20 at 11:34

1 Answers1

0

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:

  1. In your Client/ServerSession class (extends AbstractServerSession) add a getter and setter.
  2. If - and only if - you need to synchronize the values to the client implement the getter / setter like this (example for an Integer property):
  public Integer getMyProperty() {
    return getSharedContextVariable("myProperty", Integer.class);
  }

  public void setMyProperty(Integer newValue) {
    setSharedContextVariable("myProperty", Integer.class, newValue);
  }
  1. You'll need to teach the application to transfer the data to your Client or ServerSession.
  2. If your data comes from the backend side (e.g. from database): Your best guess is to override the default implementation of org.eclipse.scout.rt.server.context.HttpServerRunContextProducer. Create a subclass of this class in your .server-part, and add the @Replace annotation. Your best place to implement it is likely in the method public IServerSession getOrCreateScoutSession(HttpServletRequest req, ServerRunContext serverRunContextForSessionStart, String scoutSessionId)
  3. If your data comes from the UI side (e.g. passed by SAML): This is more complicated and I have only hints where to start looking: 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.
Patrick
  • 4,720
  • 4
  • 41
  • 71