Posts

Showing posts from October, 2015

UnderStanding the Resource Permission

This article explains about the basic flow of the resources, how they are applied. 1. Create the Portlet with the Name as "TestPermission" 2. Create service.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 6.2.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_6_2_0.dtd"> <service-builder package-path="com.service"> <author>Test</author> <namespace>Test</namespace> <entity name="Bus" local-service="true">         <column name="id" type="long" primary="true"></column>         <column name="registration" type="String"></column>         <column name="wheels" type="String"></column>     </entity> </service-builder> Build the services, automatically classes w

Working with Alloy UI Taglibs

Image
We can use readly avalible taglibs in our customportlet , Here are the some 1. If we want user to rate the content we can use "ratings" taglib as, <liferay-ui:ratings classPK="12724" className="<%=BlogsEntry.class.getName() %>"></liferay-ui:ratings> Here classPK is the  primarykey , here i am using the blogsentry so it is blogsentryid className is the classname of the entry, wheather it is "BlogsEntry" , "JournalArticle" etc. 2. If we want to display the rating score <liferay-ui:ratings-score score="2"></liferay-ui:ratings-score> 3. "Discussion" taglib mostly used to display the user comments <liferay-ui:discussion classPK="12724" userId="10201" className="<%=BlogsEntry.class.getName() %>" formAction="fm"></liferay-ui:discussion> Here classPK is the  primarykey , here i am using the blogsentry so it is

Service builder exception : org.dom4j.DocumentException: www.liferay.com Nested exception: www.liferay.com

Today, while building an service i got the following exception. Solution:    Since i don't have the internet connection. while building the services i got the below exception.    So remove the DTD from the service.xml   If still you get this exception remove from the other xml files like liferay-display.xml and liferay-portlet.xml DTD will be at lineno:1 or 2 of the service.xml It will look as below <!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 6.2.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_6_2_0.dtd"> <service-builder package-path="com.test.sample"> ................ Hope this information helps. com.liferay.portal.kernel.xml.DocumentException: www.liferay.com Nested exception: www.liferay.com at com.liferay.portal.xml.SAXReaderImpl.read(SAXReaderImpl.java:429) at com.liferay.portal.xml.SAXReaderImpl.read(SAXReaderImpl.java:447) at com.liferay.portal.kernel.xml.SAXReaderUtil.

Disabling the Change of password for the user

If we want to disable the change of the password when user is logging into first time, we can follow these 2 steps 1. When the user is creating the my code, i mean if we have written the code for adding the user instead of out of box. then we can set like this . user.setPasswordReset(false); UserLocalServiceUtil.updateUser(user); 2. I think this option we be better, Go to the controlPanel Control Panel -> Password Policies(Portal Section) -> Default Password Policy .-> Change Required (uncheck checkbox). That's it , when user is logging first time, then we cannot get change password screen.

Knowing About the layout

We can Check the page whether it is private or public page using layout object. layout.isPrivateLayout() layout.isPublicLayout() layout is an implict object in liferay By using this "layout" object we can get title , description, theme applied to that page, group, Also we can get the child page and parent page details. Forming the dynamic URL PortalUtil.getPathFriendlyURLPublic() : It retrieves "/web" PortalUtil.getPathFriendlyURLPrivateGroup() : It retrieves "/group" themeDisplay.getScopeGroup().getFriendlyURL(): It retrieves site name(ex: guest) So finally we can write as, If we want Public Page URL: PortalUtil.getPathFriendlyURLPublic()+ themeDisplay.getScopeGroup().getFriendlyURL() +StringPool.SLASH + "home"; It will be as "/web/guest/home. Also If we want Private Page URL: PortalUtil.getPathFriendlyURLPrivateGroup()+ themeDisplay.getScopeGroup().getFriendlyURL() + StringPool.SLASH

Copying array to another array

Sometimes it is required to copy array to another array, how can we do that? Here is the things, In the java.lang.system class we have System.arrayCopy(-,-.....); we can utlize these method to copy the array. Here is the method : System.arraycopy(src, srcPos, dest, destPos, length); Here we have 2 array fields , which we need to copy into the String [] finalfields array. final String [] userField = {"screenName","firstName","lastName","emailAddress","jobTitle"}; final String [] addressFields= {"streetNo","pinCode"}; Calculating the finalfields array size int fieldsSize = userField.length + addressFields.length; String [] finalfields = new String[fieldsSize]; System.arraycopy(userField, 0, finalfields, 0, userField.length); Here we have copied the "userField" array values into the "finalfields" array values. System.arraycopy(addressFields, 0, finalfields, userField.length, addressFie

Getting the Organization name.

We know we can get the Organization details from the OrganizationLocalServiceUtil. Also we have another option to get those details. It is from the GroupLocalServiceUtil. As we know that whenever we create the Organization it will be created in the " Group " table only. Here I am getting the " Test Organization" Organization Getting the Organization name from the group String defaultOrganizationGroupName = "Test Organization"; defaultOrganizationGroupName +=GroupLocalServiceImpl.ORGANIZATION_NAME_SUFFIX; Group group = GroupLocalServiceUtil.getGroup(companyId,defaultOrganizationGroupName);

Getting the Expandovalue

We can use the "ExpandoLocalServiceUtil" to get the Expando or custom field value from the Object. Also we have another option to get expando value, Here we will use the ExpandoBridge to get the value details. Below example , using the user object to get the expando values. String attributeName = "interest"; ExpandoBridge expandoBridge = user.getExpandoBridge(); if(Validator.isNotNull(expandoBridge)) { String attr = (String) expandoBridge.getAttribute(attributeName); } Here we have the customfield name as " interest " and retrieving the value of that attribute. Note : But user should have permission to get the value.

Adding Default Roles, sites and userGroup

If we want add the default "UserGroups" , "Groups" and "Roles" to the users, we can use the following methods to add. This will ensure, when user is creating it will assign these "UserGroups" , "Groups" and "Roles" to the users If we look into this " admin.default.role.names " in the portal.properties , it has User and PowerUser added, So whenever user is created, these 2 roles are assigned. Here for admin.default.user.group.names , we have added as CoffeGroup , so this group will be assigned automatically to the newly created user. Note: Whatever value we assign to the property , this should exists in the Portal. i.e  CoffeGroup (user group)should be exist in the portal, before creation of user. 1. UserGroup     #     # Input a list of default user group names separated by \n characters that     # are associated with newly created users.     #     admin.default.user.group.names=CoffeGroup UserLoca