`

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>  
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics