eclipse-scout - 如何从 Scout 客户端代码访问请求 HttpSession?
问题描述
例如,从 Scout Form execStore() 方法中,在执行任何服务器服务之前,我喜欢获取 HttpSession 并最终从其属性存储中获取自定义数据。
解决方案
正如评论中提到的,Eclipse Scout 将 UI 层(HTML 呈现 - 或旧版本中的 Swing 客户端)与客户端模型分开。虽然 UI 层知道 HttpSession,但表单所在的客户端模型却不知道。
但是,您可以将相关属性放在 ServerSession(后端)上并将它们同步到 ClientSession(模型),反之亦然 - 取决于您的属性来自何处。
这个草图应该让你开始:
- 在您的 Client/ServerSession 类 (
extends AbstractServerSession
) 中添加一个 getter 和 setter。 - 如果-且仅当-您需要将值同步到客户端,则像这样实现getter / setter(整数属性的示例):
public Integer getMyProperty() {
return getSharedContextVariable("myProperty", Integer.class);
}
public void setMyProperty(Integer newValue) {
setSharedContextVariable("myProperty", Integer.class, newValue);
}
- 您需要教应用程序将数据传输到您的客户端或服务器会话。
- 如果您的数据来自后端(例如来自数据库):您最好的猜测是覆盖
org.eclipse.scout.rt.server.context.HttpServerRunContextProducer
. 在您的 .server-part 中创建此类的子类,并添加@Replace
注释。您实现它的最佳位置可能在方法中public IServerSession getOrCreateScoutSession(HttpServletRequest req, ServerRunContext serverRunContextForSessionStart, String scoutSessionId)
- 如果您的数据来自 UI 端(例如由 SAML 传递):这更复杂,我只提示从哪里开始查找:
org.eclipse.scout.rt.ui.html.UiSession.createAndStartClientSession(Locale, UserAgent, Map<String, String>)
关于如何创建 ClientSession 以及您是否可以在此位置访问您的数据。
推荐阅读
- php - shell_exec 不会从浏览器请求中执行
- php - FPDF 无法创建图像
- python - 使用 scikit-learn 加载 .arff 文件时出错
- xcode - 找不到 -lRNFirebase React Native 的库
- angular - Angular HttpClient 删除
- notepad++ - 我想删除 Notepad++ 中所有出现的类似文本
- vue.js - 带有来自 API 调用的值的 Vue.js 进度条
- dialogflow-es - 如何在 DialogFlow 中保持麦克风打开
- javascript - 使用 jquery 过滤 D3.js 地图?
- sql - SQL:根据属性顺序对行进行排序