[Liferay] 6.2.0 版本 form 表单中的 namespace 使用

写一个不使用 aui 标签的 form 表单提交数据
代码如下 :

<form action="<portlet:actionURL />" method="POST">
<table>
  <tr>
          <td>
               <input type="text" name="email" />
          </td>
  </tr>
  <tr>
    <td>
         <input type="submit"/>
    </td>
  </tr>
</table>
</form>

在liferay 6.2 之前的版本中,在 portlet-class 内如果想获取数据:
public void processAction(ActionRequest request, ActionResponse response)
     throws PortletException, IOException {
          String email = request.getParameter("email");
          System.out.println(email);
}

这么实现是好使的,但是在版本6.2.0使用会出现无法获取的问题。是因为在6.2.0之后,Liferay为避免属性冲突,默认需要用户添加<portlet:namespace />。
所以必须修改 form 表单为:

<form action="<portlet:actionURL />" method="POST">
<table>
  <tr>
          <td>
               <input type="text" name="<portlet:namespace />email" />
          </td>
  </tr>
  <tr>
    <td>
         <input type="submit"/>
    </td>
  </tr>
</table>
</form>

当然这是默认情况,如果一定不想使用 <portlet:namespace /> 的话,Liferay也不会难为开发者。
6.2.0 之后,portlet 对应的 liferay-portlet.xml 中, <portlet> 内有一个新element, <requires-namespaced-parameters>, 默认情况下是true,为强制要求namespace,改为false则不要求。
代码如下:

 <portlet-name>test</portlet-name>
            <icon>/icon.png</icon>
            <instanceable>false</instanceable>
            <requires-namespaced-parameters>false</requires-namespaced-parameters>
            <header-portlet-css>/css/main.css</header-portlet-css>
            <footer-portlet-javascript>
                  /js/main.js
            </footer-portlet-javascript>
            <css-class-wrapper>test-portlet</css-class-wrapper>
      </portlet>


注意添加 element 的顺序是有要求的。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值