符合JSR 286的名称空间参数

编程入门 行业动态 更新时间:2024-10-26 15:28:15
本文介绍了符合JSR 286的名称空间参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在portlet中,什么是在操作方法中读取名称空间参数的最佳方法. 我的表单包含

<input id="<portlet:namespace/>param1" name="<portlet:namespace/>param1" value='hello'/>

选项1:

request.getParameter(response.getNamespace() + "param1");

选项2:

request.getParameter("param1");

option1在liferay中不起作用,但似乎在websphere中起作用. option2在liferay 6.2中可以正常工作. option1似乎可以在6.1之前的版本中使用.

有人可以告诉我什么是jsr 286兼容方式吗?

解决方案

正如我在对此问题的答案的评论中提到的那样,问题在于Liferay 6.2,因为IBM WebSphere和Liferay的早期版本可以按预期工作. /p>

为解决此问题,我将元素<requires-namespaced-parameters>false</requires-namespaced-parameters>添加到portlet的/WEB-INF目录的liferay-portlet.xml中.这样,就不会对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页顶部):

如果Portlet名称空间或对URL参数或表单参数进行编码,则它们还负责删除名称空间. Portlet容器将不会删除Portlet在这些参数上所做的任何命名间隔."

In portlet What is the best way to read namespace parameter in action method. My form contains

<input id="<portlet:namespace/>param1" name="<portlet:namespace/>param1" value='hello'/>

option1:

request.getParameter(response.getNamespace() + "param1");

option2:

request.getParameter("param1");

option1 does not work in liferay, but does seem will work in websphere. option2 works fine in liferay 6.2. option1 seems to work in before 6.1.

Can anyone please tell me what is the jsr 286 compliant way?

解决方案

As I mentioned in a comment of an answer to this question, the problem is with Liferay 6.2 because IBM WebSphere and previous versions of Liferay are working as expected.

To solve this problem, I added the element <requires-namespaced-parameters>false</requires-namespaced-parameters> to the liferay-portlet.xml of the /WEB-INF directory of the portlet. By doing this, the parameters of the HTML forms are not "namespaced".

Example of /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>

If you add this element to the liferay-portlet.xml, the portlet still works correctly in previous versions of Liferay (I tested with versions 5.5 and 6.1). It also works with other portlet contains because they ignore this file.

I claim that Liferay is behaving incorrectly because the JSR-286 spec says the following (top the page 76 of the spec):

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."

更多推荐

符合JSR 286的名称空间参数

本文发布于:2023-10-07 17:23:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1470013.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:名称   参数   空间   JSR

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!