java - 唯一标识 JSR-168 portlet 的实例

标签 java portlet

我正在编写一个可以多次添加到容器中的 JSR-168 portlet。每个容器(Liferay、JBoss 等)都有自己的内部方式来区分同一 portlet 的多个实例。

但是,我希望在 doView() 方法本身内唯一标识我的 portlet 实例。

是否有任何标准的 JSR-168 机制来检索对于我的 portlet 的每个实例都不同的一些唯一标识符?我见过各种解决方案,人们 randomly generate唯一 ID 并将它们保存在 session 中,但我更喜欢一种标准机制(如果存在)。

最佳答案

Portlet 1.0 (168) 提供 RenderResponse.getNamespace()方法,每个 portlet 实例应该是唯一的。

来自规范:PLT.12.3.4 命名空间编码:

The getNamespace method must provide the portlet with a mechanism that ensures the uniqueness of the returned string in the whole portal page. For example, the getNamespace method would return a unique string that could be prefixed to a JavaScript variable name within the content generated by the portlet, ensuring its 5 uniqueness in the whole page. The getNamespace method must return the same value if invoked multiple times within a render request.

如果您想在 processAction 中访问它,您可能希望将其存储在 session 中或作为 actionURL 参数。

如果可以选择升级,则 Portlet 2.0 (286) 会更改底层 PortletResponse 接口(interface)以提供 getNamespace() 方法,并添加 PortletRequest.getWindowID () 方法可能对您有用。

关于java - 唯一标识 JSR-168 portlet 的实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/388394/

相关文章:

liferay - 从 Configuration.jsp 调用 Action-Class

java - 在Java中,当捕获异常时,返回到for循环

java - 这种软件风格叫什么?

java - gwt-maven-插件 : Only generate necessary js files

java - 作业调度 - 如何为基于 Spring MVC 的应用程序选择最好的作业调度

java - Liferay 链接到具有特定操作的另一个 portlet

java - 无法使用搜索工具在 liferay portlet 中搜索期刊文章

java - 使用 Portlet 比只使用服务器端包含有何优势?

Java如何在不干扰的情况下监听端口上的流量

java - 所有问题一一显示后,我想再次显示第一条消息