Friday 25 May 2012

Write a dynamic query in liferay.


Created a query to find a Categories which has "country" into its name.

DynamicQuery dynamicQuery =DynamicQueryFactoryUtil.forClass(MBCategory.class,PortalClassLoaderUtil.getClassLoader());
        dynamicQuery.add(PropertyFactoryUtil.forName("name").like("%Country %"));

Return the category list which has country into its name.
List<MbCategory> categories =  MBCategoryLocalServiceUtil.dynamicQuery(dynamicQuery);

Friday 18 May 2012

Example Of search container in liferay

Fetched the threads for the particular category.

List<MBThread>  threads= MBThreadLocalServiceUtil.getThreads(themeDisplay.getScopeGroupId(), 10010, 0, -1, -1);

Once fetched the threads of the particular show the result using the search container. If there is no results in the it is going to give the message no posts found which is going to fetch from the language.properties.


<liferay-ui:search-container delta="5" emptyResultsMessage="no-posts-found">
    <liferay-ui:search-container-results
        results="<%=ListUtil.subList(threads, searchContainer.getStart(), searchContainer.getEnd()) %>"
        total="<%=threads.size()%>">

    </liferay-ui:search-container-results>
<%--class name is the class which type of the list we have created for the search iterator.key property is the primary key for that value and modelVar is the variable

ofclassName type--%>

    <liferay-ui:search-container-row
        className="com.liferay.portlet.messageboards.model.MBThread"
        keyProperty="threadId" modelVar="thread">

<%--For putting the value of the each column using the liferay-ui:search-container-column-text.name is the column name and the value is the value want to put into the column.  --%>

<%--Name --%>
        <liferay-ui:search-container-column-text name="Topic"
            value="<%= MBMessageLocalServiceUtil.getMessage(thread.getRootMessageId()).getSubject()%>" />
       
    </liferay-ui:search-container-row>

   <liferay-ui:search-iterator />

</liferay-ui:search-container>





If want to define own message in to custom portlet make entry following property into the <resource-bundle>com.qad.userprofile.content.Language</resource-bundle> . make the package com.qad.userprofile.content and put the language.properties file into that bundle.

Show the dock bar to the Particular group of user in theme in liferay

In the init-custom.vm
To access the UserLocalServicewrite the following line
#set ($userLocalService = $serviceLocator.findService("com.liferay.portal.service.UserLocalService"))


to access the UserGroupLocalServiceUtil added the following line.
#set ($userGroupLocalService = $serviceLocator.findService("com.liferay.portal.service.UserGroupLocalService"))



Get the user group with the name web content moderator
#set ($userGroup = $userGroupLocalService.getUserGroup($user.getCompanyId(),$propsUtil.get("WebContentModerator)))


If the ser group exist and if the user is part of that user group then returns value true.


#if($userGroup)
    #set ($hasUserGroupRole = $userLocalService.hasUserGroupUser($userGroup.getUserGroupId(),$user.getUserId()))
#end

in the portal_normal.vm

#if ($is_signed_in && $hasUserGroupRole))
    #dockbar()
#end