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
submitForm(document.
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,