Liferay7 BPM门户开发之39: Form表单提交的ProcessAction处理
Posted 昕友软件开发
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Liferay7 BPM门户开发之39: Form表单提交的ProcessAction处理相关的知识,希望对你有一定的参考价值。
在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处理的主要内容,如果未能解决你的问题,请参考以下文章
Liferay7 BPM门户开发之37: Liferay7下的OSGi Hook集成开发
Liferay7 BPM门户开发之17: Portlet 生命周期
Liferay7 BPM门户开发之3: Activiti开发环境搭建
Liferay7 BPM门户开发之14: Liferay开发体系简介