在 portlet 中,读取操作方法中的命名空间参数的最佳方法是什么。 我的表单包含
<input id="<portlet:namespace/>param1" name="<portlet:namespace/>param1" value='hello'/>
选项1:
request.getParameter(response.getNamespace() + "param1");
选项2:
request.getParameter("param1");
选项1在liferay中不起作用,但似乎在websphere中起作用。 option2 在 liferay 6.2 中工作正常。 option1 似乎在 6.1 之前有效。
谁能告诉我什么是 jsr 286 兼容方式?
最佳答案
正如我在对该问题的回答的评论中提到的,问题出在 Liferay 6.2 上,因为 IBM WebSphere 和以前版本的 Liferay 正在按预期工作。
为了解决这个问题,我添加了元素 <requires-namespaced-parameters>false</requires-namespaced-parameters>
到liferay-portlet.xml
/WEB-INF
的portlet 的目录。通过这样做,HTML 表单的参数就不会被“命名空间”。
/WEB-INF/liferay-portlet.xml
的示例:
<?xml version="1.0" encoding="UTF-8"?>
<liferay-portlet-app>
<portlet>
<portlet-name>Portlet name</portlet-name>
<requires-namespaced-parameters>false</requires-namespaced-parameters>
<instanceable>true</instanceable>
<ajaxable>false</ajaxable>
</portlet>
</liferay-portlet-app>
如果将此元素添加到 liferay-portlet.xml
,该 portlet 在 Liferay 的早期版本中仍然可以正常工作(我使用版本 5.5 和 6.1 进行了测试)。它也适用于其他包含的 portlet,因为它们会忽略此文件。
我声称 Liferay 行为不正确,因为 JSR-286 规范有以下规定(规范第 76 页顶部):
If portlets namespace or encode URL parameters or form parameters they are also responsible for removing the namespace. The portlet container will not remove any namespacing the portlet has done on these parameters."
关于portlet - 符合 JSR 286 的命名空间参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21550030/