符合JSR 286的名称空间参数 [英] JSR 286 compliant namespace parameter

查看:123
本文介绍了符合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的名称空间参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆