【问题标题】:How can I access the request HttpSession from Scout client side code?如何从 Scout 客户端代码访问请求 HttpSession?
【发布时间】:2020-11-06 05:27:26
【问题描述】:

例如,通过 Scout Form execStore() 方法,在执行任何服务器服务之前,我喜欢获取 HttpSession 并最终从其属性存储中获取自定义数据。

【问题讨论】:

  • Eclipse Scout 将 UI 层(HTML 呈现 - 或旧版本中的 Swing 客户端)与客户端模型分开。虽然 UI 层知道 HttpSession,但表单所在的客户端模型却不知道。您能描述一下您要解决的问题吗?
  • 谢谢,这就解释了为什么我无法从客户区获得 HttpSession。我正在尝试将自定义数据附加到登录的用户,目前我通过自定义授权代码(UI 层)将这些数据加载到 HttpSession attrs。
  • 我正在寻找一种更好的方法来让这些会话数据在服务调用服务器之前可用。

标签: eclipse-scout


【解决方案1】:

如 cmets 中所述,Eclipse Scout 将 UI 层(HTML 呈现 - 或旧版本中的 Swing 客户端)与客户端模型分开。虽然 UI 层知道 HttpSession,但表单所在的客户端模型却不知道。

但是,您可以将相关属性放在 ServerSession(后端)上并将它们同步到 ClientSession(模型),反之亦然 - 取决于您的属性来自何处。

这个草图应该让你开始:

  1. 在您的 Client/ServerSession 类 (extends AbstractServerSession) 中添加一个 getter 和 setter。
  2. 如果 - 且仅当 - 您需要将值同步到客户端,请像这样实现 getter/setter(整数属性的示例):
  public Integer getMyProperty() {
    return getSharedContextVariable("myProperty", Integer.class);
  }

  public void setMyProperty(Integer newValue) {
    setSharedContextVariable("myProperty", Integer.class, newValue);
  }
  1. 您需要指导应用程序将数据传输到您的 Client 或 ServerSession。
  2. 如果您的数据来自后端(例如来自数据库):您最好的猜测是覆盖org.eclipse.scout.rt.server.context.HttpServerRunContextProducer 的默认实现。 在您的 .server-part 中创建此类的子类,并添加 @Replace 注释。你最好的实现它的地方可能是方法public IServerSession getOrCreateScoutSession(HttpServletRequest req, ServerRunContext serverRunContextForSessionStart, String scoutSessionId)
  3. 如果您的数据来自 UI 端(例如通过 SAML 传递): 这更复杂,我只提示从哪里开始查找:org.eclipse.scout.rt.ui.html.UiSession.createAndStartClientSession(Locale, UserAgent, Map<String, String>) 关于如何创建 ClientSession 以及您是否可以在此位置访问您的数据。

【讨论】:

    猜你喜欢
    • 2015-03-05
    • 1970-01-01
    • 1970-01-01
    • 2017-05-15
    • 2016-07-27
    • 2020-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多