Posts

Showing posts from October, 2013

Information about the service builder(service.xml) - data is deleted whenever we are deploying the portlet in liferay

Whenever we are writing the service.xml , we must be ensure the following condition <column name="frameworkVersionId" type="long" primary="true" id-type="increment" /> Dont use  id-type="increment" in cluster environment because when ever you are deploying the portlet data will be deleted and as it will be as new table. Ensure whenever your writing the  id-type="increment" for the primary key generation.

Many-to-Many relationship in liferay using service builder

Not only one-many relationship , we can also define many-to-many relationship using service builder If the entity and mapping-key attributes are specified and mapping-table is not, then the Service Builder will assume you are specifying a one to many relationship. For example: <column name="shoppingItemPrices" type="Collection" entity="ShoppingItemPrice" mapping-key="itemId" /> If the entity and mapping-table attributes are specified and mapping-key is not, then the Service Builder will assume you are specifying a many to many relationship. For example: <column name="roles" type="Collection" entity="Role" mapping-table="Groups_Roles" /> The above items are mentioned in DTD of service.xml , Download the DTD for more details.

One to Many Relationship in liferay using service bulider

Sometimes It is required to set relationship in liferay through the service.xml  <entity name="Parent" local-service="true" remote-service="false"> <column name="ParentId" type="long" primary="true" />                  <column name="childReference" type="Collection" entity="ChildReference" mapping-key="ChildId" />                -------------------               ------------------- </entity>  <entity name="Child" local-service="true" remote-service="false"> <column name="ChildId" type="long" primary="true" />                -------------------               ------------------- </entity> Thats it you have set one-to-many relationship Then build your service , to see the auto generated classes Refer the ParentUtil class to see the mapping classes .

Setting Page title in liferay

  Hi,   Some it requires to set page title , this following sniptess will be useful  HttpServletRequest request= PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(renderRequest));   PortalUtil.setPageTitle("Home - Page",request); Interally liferay using following snipets to set Page title in PortalImpl class public void addPageTitle(String title, HttpServletRequest request) { String requestTitle = (String)request.getAttribute(WebKeys.PAGE_TITLE); if (requestTitle != null) { title = requestTitle + StringPool.SPACE + title; } request.setAttribute(WebKeys.PAGE_TITLE, title); }   

Dynamic Query power in liferay

Navigate to the following URL to know how the dynamic query works, it clearly explains. http://liferayjavafunwithjay.blogspot.in/2012/01/power-of-dynamic-query-in-liferay.html Lately I came across a scenario while developing portlet in Liferay in which simple queries were not enough & I was required to fetch data on many different conditions. To simply the things, consider following scenario: There is one model (In Liferay's terms Entity / POJO) called "Request" generated by service builder having fields like request Id, status, requestor Id, department, shipment address, date, updator Id, next Approver Id etc. Now at run-time, I was required to show data by combining various conditions based on user’s actions like when ((requestorId == 1000 || nextApproverId == 1000) && (status == “PENDING”) ) ((address ==”NJ”)  &&  (status == “PENDING” || status == “NEW” || status == “INPROCESS”) )       In above 2 conditions mentioned in pseudo code,

Disabling the cache for entity and also finder

 In Liferay sometimes its need to disable cache, here it is how its works,  Suppose if we need to disable cache for BlogsEntry entity  Put following properties in portal-ext.properties     1.value.object.entity.cache.enabled.com.liferay.portlet.blogs.model.BlogsEntry = false;         For clarity look at the class" BlogsEntryModelImpl.java "         Similarly we can disable cache for finder of blogsEntry is as ,    2. value.object.finder.cache.enabled.com.liferay.portlet.blogs.model.BlogsEntry = false;

Inserting Objects in *.ServiceImpl.java

  By default liferay provides some objects injected. 1. counterLocalService 2. userLocalService     userService     userPersistance 3. resourceLocalService     resourceService     resourcePersistance       and etc....  So we inject other services by using reference tag in service.xml         <reference package-path="com.liferay.portlet.asset" entity="AssetEntry" /> Here we are inserting assetEntryLocalService