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

2019-04-22 21:53

Liferay 6 Development Documentation

name varchar(100) default NULL, qty int(11) default NULL, comment varchar(100) default NULL, date_added timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, PRIMARY KEY (uuid) ) ENGINE=InnoDB DEFAULT CHARSET=utf8

2. Create product_service.xml to generate source code

File path:

/myliferay/docroot/WEB-INF/ext-impl/src/com/accentrix/ecatalog/product/product_service.xml product You should add or remove a table column in this file. 3. Create build.xml for to run the product_service.xml

File path: /myliferay/docroot/WEB-INF/ext-impl/src/com/accentrix/ecatalog/product/build.xml Run the build file auto generate source code under below path:

/myliferay/docroot/WEB-INF/ext-impl/src/com/accentrix/ecatalog/product/model/impl /myliferay/docroot/WEB-INF/ext-impl/src/com/accentrix/ecatalog/product/service/base /myliferay/docroot/WEB-INF/ext-impl/src/com/accentrix/ecatalog/product/service/impl /myliferay/docroot/WEB-INF/ext-impl/src/com/accentrix/ecatalog/product/service/persistence

Liferay 6 Development Documentation

Notice: a) b)

Please noted that path must be right, otherwise will not create successfully.

Since this class is auto generated, you should never modify it, or your changes will be overwritten the next time you run Service Builder. Instead, all custom code should be placed in XXXLocalServiceImpl.

4. Add a method to the service layer.

Add the following method to to ProductLocalServiceImpl.java File path:

/myliferay-ext/docroot/WEB-INF/ext-impl/src/com/accentrix/ecatalog/product/service/impl/ProductLocalServiceImpl.java

package com.accentrix.ecatalog.product.service.impl; import java.util.List;

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

import com.accentrix.ecatalog.product.service.base.ProductLocalServiceBaseImpl; import com.liferay.portal.kernel.exception.SystemException; /**

* @author tom.wu * */

public class ProductLocalServiceImpl extends ProductLocalServiceBaseImpl { }

public List findByName(String name, int start, int end) throws SystemException { }

public int countByName(java.lang.String name) throws SystemException { }

int count = productPersistence.countByName(name); return count;

List list = productPersistence.findByName(name, start, end); return list;

5. Add ProductSearch.java for search result

File path:

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

package com.accentrix.ecatalog.product.action; import java.util.ArrayList; Liferay 6 Development Documentation

import java.util.HashMap; import java.util.List; import java.util.Map;

import javax.portlet.PortletRequest; import javax.portlet.PortletURL;

import com.accentrix.ecatalog.product.model.Product; import com.liferay.portal.kernel.dao.search.SearchContainer; import com.liferay.portlet.enterpriseadmin.search.RoleDisplayTerms; /**

* @author tom.wu * */

public class ProductSearch extends SearchContainer {

public ProductSearch(PortletRequest portletRequest, PortletURL iteratorURL) {

super(portletRequest, new RoleDisplayTerms(portletRequest), new ProductSearchTerms(portletRequest), public static final String EMPTY_RESULTS_MESSAGE = \; static { }

headerNames.add(\); headerNames.add(\); headerNames.add(\);

static List headerNames = new ArrayList();

static Map orderableHeaders = new HashMap();

DEFAULT_CUR_PARAM, DEFAULT_DELTA, iteratorURL, headerNames, EMPTY_RESULTS_MESSAGE); }

}

6. Create ProductSearchTerms.java for search term query.

File path:

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

package com.accentrix.ecatalog.product.action; import javax.portlet.PortletRequest; Liferay 6 Development Documentation

import com.liferay.portal.kernel.dao.search.DAOParamUtil; import com.liferay.portal.kernel.dao.search.DisplayTerms; /**

* @author tom.wu * */

public class ProductSearchTerms extends DisplayTerms { }

public void setName(String name) { }

this.name = name; public String getName() { }

return name;

public ProductSearchTerms(PortletRequest portletRequest) { }

super(portletRequest);

// name = ParamUtil.getString(portletRequest, NAME); name = DAOParamUtil.getLike(portletRequest, NAME); public String name;

public static final String NAME = \

7. Update ProductAction.java (already added in second part)

File path:

/myliferay-ext/docroot/WEB-INF/ext-impl/src/com/accentrix/ecatalog/product/action/ProductAction.java /** * */ package com.accentrix.ecatalog.product.action; import java.util.List; import javax.portlet.PortletConfig; import javax.portlet.PortletURL; import javax.portlet.RenderRequest; Liferay 6 Development Documentation

import javax.portlet.RenderResponse; import javax.portlet.WindowState;

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.dao.search.ResultRow; import com.liferay.portal.kernel.util.ParamUtil; import com.liferay.portal.struts.PortletAction; /**

* @author tom.wu * */

public class ProductAction extends PortletAction {

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

RenderResponse res) throws Exception {

List results = ProductLocalServiceUtil.findByName(searchTerms.getName(), searchContainer.getStart(),

ProductSearchTerms searchTerms = (ProductSearchTerms) searchContainer.getSearchTerms();

// set table header

ProductSearch searchContainer = new ProductSearch(req, portletURL); searchContainer.setDeltaConfigurable(false);

// search term,return all result if name is null String name = ParamUtil.getString(req, \PortletURL portletURL = res.createRenderURL(); portletURL.setWindowState(WindowState.MAXIMIZED);

portletURL.setParameter(\portletURL.setParameter(\

searchContainer.getEnd());

for (int i = 0; i < results.size(); i++) {

searchContainer.setTotal(total); searchContainer.setResults(results);

List resultRows = searchContainer.getResultRows(); req.setAttribute(\

int total = ProductLocalServiceUtil.countByName(searchTerms.getName());


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

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

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

马上注册会员

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