码迷,mamicode.com
首页 > 其他好文 > 详细

Liferay7 BPM门户开发之39: Form表单提交的ProcessAction处理

时间:2016-11-27 23:54:45      阅读:624      评论:0      收藏:0      [点我收藏+]

标签:rtl   over   tab   life   方式   style   package   alt   vax   

在v6.2开始后,需要设置<requires-namespaced-parameters>false</requires-namespaced-parameters>  来避免在jsp中写<portlet:namespace/>的input前缀

在v7.0发现,注解方式是不灵的!

即  "javax.portlet.requires-namespaced-parameters=false", 无效果, 真是汗...

但我们是有办法在7.0中解决的,直接上代码

jsp:

<%@page import="com.liferay.portal.kernel.portlet.LiferayPortletMode"%>
<%@page import="com.liferay.portal.kernel.portlet.LiferayWindowState"%>
<%@ include file="/init.jsp" %>

<p>
    <b><liferay-ui:message key="com_lifiti_parts_ComLifitiPartsmvcportlet.caption"/></b>
</p>


<liferay-portlet:renderURL var="openPortletURL" copyCurrentRenderParameters="true" portletMode="<%=LiferayPortletMode.VIEW.toString() %>" 
  windowState="<%=LiferayWindowState.NORMAL.toString()%>">
  <liferay-portlet:param name="param" value="参数的值"/>
</liferay-portlet:renderURL>
<c:set var="submit"><liferay-ui:message key="com_lifiti_parts_ComLifitiPartsmvcportlet.submit"/></c:set>
<a href="${openPortletURL}">Render Url created</a>

<portlet:actionURL var="sendURL" name="send">  
</portlet:actionURL>  
  
<form action="${sendURL}" method="post" name="fm">  
    <aui:input name="name" label="Name" id="name"/> 
    <input type="text" id="age" name="age" />  
    <input type="text" name="<portlet:namespace/>phone" />  
     <input type="submit" value="${submit}"></input>  
</form>  

 

portlet java

package com.lifiti.portlet;

import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet;
import com.liferay.portal.kernel.util.ParamUtil;

import java.io.IOException;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.Portlet;
import javax.portlet.PortletException;
import javax.portlet.ProcessAction;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

import org.osgi.service.component.annotations.Component;

@Component(
    immediate = true,
    property = {
        "com.liferay.portlet.display-category=category.sample",
        "com.liferay.portlet.instanceable=true",
        "javax.portlet.requires-namespaced-parameters=false",没效果!
        "javax.portlet.display-name=com.lifiti.parts Portlet",
        "javax.portlet.init-param.template-path=/",
        "javax.portlet.init-param.view-template=/view.jsp",
        "javax.portlet.resource-bundle=content.Language",
        "javax.portlet.security-role-ref=power-user,user"
    },
    service = Portlet.class
)
public class FirstPortlet extends MVCPortlet {
  private static final Log _log = LogFactoryUtil.getLog(FirstPortlet.class.getName());
  
  @Override
  public void render(RenderRequest request, RenderResponse response)
  throws PortletException, IOException {
   _log.info(" This is render method of RenderURLByLiferayTagPortlet");
  
    String data = request.getParameter("param");
    String data1= ParamUtil.getString(request, "param","");
    System.out.println("parameter with request.getParameter is =>"+data);
    System.out.println("parameter with ParamUtil.getString is =>"+data1);
    
   super.render(request, response);
  }
  
  @ProcessAction(name="send")  
  public void ReceiveData(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception {  
      String name = ParamUtil.getString(actionRequest, "name"); 
      String age = ParamUtil.getString(actionRequest, "age"); 
      String phone = ParamUtil.getString(actionRequest, "phone"); 
          _log.info(" 开始接收数据");
          System.out.println("FirstPortlet.java  name = " + name);  
          System.out.println("FirstPortlet.java  age = " + age);  
          System.out.println("FirstPortlet.java  phone = " + phone);  
      }  
}

 

界面:

技术分享

运行的结果:

name = 王昕

age =

phone = 123

 

我们发现age是空的,看来说明如果用input元素,那还得写<portlet:namespace/> ,要么就用AUI,应该问题会比较少

 

Liferay7 BPM门户开发之39: Form表单提交的ProcessAction处理

标签:rtl   over   tab   life   方式   style   package   alt   vax   

原文地址:http://www.cnblogs.com/starcrm/p/6107183.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!