gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 01:40:33 24 4
gpt4 key购买 nike

我正在编写一个可以多次添加到容器中的 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com