Featured post

Docker setup for Liferay 7 with MySQL

Monday, 9 April 2012

Unable to create friendly url mapping with javascript in Liferay



I've set up friendly URL routing for my Liferay portlet, and it's working fine when I generate URLs with the standard JSP tags like so:
<portlet:renderURL var="resetUrl">
    <portlet:param name="start" value="5" />
</portlet:renderURL>
which, given my mapping, produces a lovely URL like:
localhost:8080/web/guest/welcome/-/myportlet/5
But when I generate URLs using the JavaScript PortletURL module, I get the full unfriendly URL. For instance:
var filterUrl = Liferay.PortletURL.createRenderURL();
filterUrl.setPortletId("<%= portletDisplay.getId() %>");
filterUrl.setParameter("start", "5");
location.href = filterUrl;
will generate
localhost:8080/web/guest/welcome?p_p_id=myportlet_WAR_MyPortletportlet&p_p_lifecycle=0&myportlet_WAR_MyPortletportlet_start=5
So the question is: How can I generate friendly URLs from JavaScript?


Solution : Here is the Hack - Just give it a try
<portlet:renderURL var="resetUrl">
    <portlet:param name="start" value="changeStart" />
</portlet:renderURL>
then write javascript and replace param values like this -
function createStart(copyNavigationPointURL) {
    var start = document.getElementById("navigationPointId").value;

    copyNavigationPointURL = copyNavigationPointURL.replace(/changeStart/i,start);
    submitForm(document.hrefFm, copyNavigationPointURL);
}
And you have your friendly url ....
localhost:8080/web/guest/welcome/-/myportlet/5

Your are just done, Try & Enjoy the function.....:)

Tuesday, 3 April 2012

How to migrate existing data and configure to use image.hook.impl or dl.hook.impl in Liferay

Sometimes we have to change the File storage Location through HOOK IMPL to Database or File System.
In that scenario we also have to migrate existing data which is already stored through previous HOOK.

Here is the solution -

1) Go to Document library/image gallery,click Export/import option on the top of rightside of the portlet,
click 'export' button for export the content & save the lar.

2) Stop the server and add "image.hook.impl=com.liferay.portal.image.FileSystemHook" in portal-ext properties
& comment the "#image.hook.impl=com.liferay.portal.image.DatabaseHook" in portal-ext properties.

3) Clear the database cache from serverAdministration and delete work temp folders in tomcat.

4) Start the server, Go to Document library/image gallery and 'import' the lar file.

Please let me know if you have any questions.



Your are just done, Try & Enjoy the function.....:)

Tuesday, 14 February 2012

Add Hidden/Admin portlets in Add more Applications Menu (Liferay)

Most of the requirement from the client comes by saying that they want the same user portlet as available in Control Panel. This can be achieved by below details.

1) Create a hook name addUserToAddApplication.
2) Create structure WEB-INF/jsp/html/portlet/layout_configuration.
3) copy view_category.jsp from source html/portlet/layout_configuration.
4) Add below lines in your jsp on line no 53 just above the while loop -

//   Use your own Category.

if(Validator.equals(portletCategory.getName(),"CATEGORY.NAME"))
{
     // 125 is portlet id of ENTERPRISE_ADMIN_USER PORTLET.

Portlet userportlet = PortletLocalServiceUtil.getPortletById(user.getCompanyId(), "125");
portlets.add(userportlet);
}

5) Deploy your hook.
6) Check your Add Application menu, you are free to add user portlet to your page.

Try & Enjoy the function....:))

Thursday, 26 January 2012

Column base sorting in Liferay's Search Container with BeanComparator.


Sometimes we have such requirement that we need sorting on our column basis,
   like by clicking on column it gives us sorted data in ascending/descending form.
You can define which column you want to sort and by which order.

By using BeanComparator, it gives you  flexibility not to create your own comparators.

1) Declare String variables to define order by column and order by type

String orderByCol = ParamUtil.getString(request, "orderByCol");
String orderByType = ParamUtil.getString(request, "orderByType");
if(orderByCol==null || orderByCol.equals(StringPool.BLANK)) {
request.setAttribute("orderByCol",orderByCol);
}
if(orderByType==null || orderByType.equals(StringPool.BLANK)) {
orderByType="asc";            //Default value for order by type
request.setAttribute("orderByType",orderByType);
}

// In your liferay Search Container pass this param orderByCol and orderByType

<liferay-ui:search-container  orderByCol="<%=orderByCol %>" orderByType="<%=orderByType %>" delta="10">

2) BeanComparator beanComparator=new BeanComparator(orderByCol);

if(orderByType.equals("desc"))
{
Collections.sort(list_Details,Collections.reverseOrder(beanComparator));
orderByType="asc";
}
else
{
Collections.sort(list_Details);
orderByType="desc";
}

//You have to make a copy of this list, otherwise it will throw an exception.

List<Test> copy_List_Details = list_Details;

// Assign it to results object of Search Container

results = ListUtil.subList(list_Details, searchContainer.getStart(), searchContainer.getEnd());

3)
                  //In your column's of Search Container make orderable true and pass orderableProperty,
                  //you can sort by as many colums as you want.


     <liferay-ui:search-container-column-text
     name="Start Date"
       value="<%=sDate_dis %>"
       orderable="<%=true %>"
         orderableProperty="regiStartDate"
     />


You are done with sorting, Try and Enjoy ....:))