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
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
public int countByName(java.lang.String name) throws SystemException { }
int count = productPersistence.countByName(name); return count;
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
static Map
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());