Liferay6 开发 环境部署 Liferay6实例(6)

2019-04-22 21:53

Liferay 6 Development Documentation

import com.liferay.portal.util.WebKeys; import com.liferay.portlet.ActionRequestImpl; import com.liferay.portlet.PortletURLImpl; /**

* @author tom.wu * */

public class ProductSaveAction extends PortletAction {

@Override

public void processAction(ActionMapping mapping, ActionForm form, PortletConfig portletConfig, ActionRequest

actionRequest, ActionResponse actionResponse) throws Exception {

protected String getRedirctURL(PortletConfig portletConfig, ActionRequest actionRequest) throws Exception {

ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); PortletURLImpl

portletURL

=

new

PortletURLImpl((ActionRequestImpl)

actionRequest,

}

} catch (Exception e) { }

String url = this.getRedirctURL(portletConfig, actionRequest); super.sendRedirect(actionRequest, actionResponse, url);

SessionErrors.add(actionRequest, e.getClass().getName()); setForward(actionRequest, \

return;// required,otherwise will continue to next line

Form fm = (Form) form;

Product product = new ProductImpl(); product.setName(fm.getName()); product.setQty(fm.getQty());

product.setComment(fm.getComment()); ProductLocalServiceUtil.addProduct(product);

try {

// If you need validation,add the checking code here. // if (1 == 1) {

// throw new Exception(\// }

portletConfig.getPortletName(), themeDisplay.getPlid(), PortletRequest.RENDER_PHASE);

}

portletURL.setWindowState(WindowState.MAXIMIZED);

portletURL.setParameter(\return portletURL.toString();

Liferay 6 Development Documentation

}

}

public void setComment(String comment) { }

this.comment = comment;

public String getComment() { }

return comment;

public void setQty(int qty) { }

this.qty = qty;

public int getQty() { }

return qty;

public void setName(String name) { }

this.name = name;

public String getName() { }

return name;

public void setUuid(String uuid) { }

this.uuid = uuid;

public String getUuid() { }

return uuid;

public static class Form extends ActionForm {

private String uuid;

private String name; // product name private int qty;

private String comment;

Deploy & restart server, we can test the add product function.

14. Add ProductEditAction.java

File path:

/myliferay-ext/docroot/WEB-INF/ext-impl/src/com/accentrix/ecatalog/product/action/Product

Liferay 6 Development Documentation

EditAction.java

/** * */

package com.accentrix.ecatalog.product.action;

import javax.portlet.PortletConfig; import javax.portlet.RenderRequest; import javax.portlet.RenderResponse;

import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping;

import com.accentrix.ecatalog.product.model.Product;

import com.accentrix.ecatalog.product.service.ProductLocalServiceUtil; import com.liferay.portal.kernel.util.ParamUtil; import com.liferay.portal.struts.PortletAction; /**

* @author tom.wu * */

public class ProductEditAction extends PortletAction {

public ActionForward render(ActionMapping mapping, ActionForm form, PortletConfig config, RenderRequest req,

RenderResponse res) throws Exception { }

}

String uuid = ParamUtil.getString(req, \if (uuid != null) { }

return mapping.findForward(\

Product product = ProductLocalServiceUtil.getProduct(uuid); req.setAttribute(\

15. Add product edit JSP

File path:

/myliferay-ext/docroot/WEB-INF/ext-web/docroot/html/portlet/product/product_edit.jsp

<%@ include file=\<%@taglib uri=\<%@ page import=\<% String redirect = ParamUtil.getString(request, \Liferay 6 Development Documentation

%>

\method=\name=\onSubmit='<%= \\+ renderResponse.getNamespace() + \

function updateProduct() { }

submitForm(document.productForm);

16. Add ProductUpdate.java

File path:

/myliferay-ext/docroot/WEB-INF/ext-impl/src/com/accentrix/ecatalog/product/action/ProductUpdateAction.java

/** * */ package com.accentrix.ecatalog.product.action; import javax.portlet.ActionRequest; import javax.portlet.ActionResponse; Liferay 6 Development Documentation

import javax.portlet.PortletConfig; import javax.portlet.PortletRequest; import javax.portlet.WindowState;

import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionMapping;

import com.accentrix.ecatalog.product.action.ProductSaveAction.Form; import com.accentrix.ecatalog.product.model.Product;

import com.accentrix.ecatalog.product.model.impl.ProductImpl; import com.accentrix.ecatalog.product.service.ProductLocalServiceUtil; import com.liferay.portal.kernel.util.ParamUtil; import com.liferay.portal.struts.PortletAction; import com.liferay.portal.theme.ThemeDisplay; import com.liferay.portal.util.WebKeys; import com.liferay.portlet.ActionRequestImpl; import com.liferay.portlet.PortletURLImpl; /**

* @author tom.wu * */

public class ProductUpdateAction extends PortletAction {

@Override

public void processAction(ActionMapping mapping, ActionForm form, PortletConfig portletConfig, ActionRequest

actionRequest, ActionResponse actionResponse) throws Exception {

protected String getRedirctURL(PortletConfig portletConfig, ActionRequest actionRequest, String uuid) throws }

String url = this.getRedirctURL(portletConfig, actionRequest, fm.getUuid()); super.sendRedirect(actionRequest, actionResponse, url);

Form fm = (Form) form;

Product product = new ProductImpl(); product.setUuid(fm.getUuid()); product.setName(fm.getName()); product.setQty(fm.getQty());

product.setComment(fm.getComment()); ProductLocalServiceUtil.updateProduct(product);

Exception {

String redirect = ParamUtil.getString(actionRequest, \

ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); PortletURLImpl

portletURL

=

new

PortletURLImpl((ActionRequestImpl)

actionRequest,


Liferay6 开发 环境部署 Liferay6实例(6).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:岗位手册-制单员(展厅)

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: