Tuesday, 15 April 2014

Resolving Service builder issues in Liferay

Recently I ran into some issues when trying to use Liferay service builder utility. Although I was working with Liferay CE 6.2 this post should be helpful for any Liferay version.

For the first time when I ran service builder it worked fine and generated the tables. But then I changed the namespace entry in service.xml file. This change did not update the database table. So I deleted the table and tried to run service builder again and redeploy the portlet. But this resulted in errors during portlet deployment.

Friday, 11 April 2014

Upload files and access form elements in a custom Portlet - Using multipart/form-data and UploadPortletRequest

This blog post will help you if you are looking to add form upload functionality to your JSP form and then access it in your controller, java class.

For this blog post I have used Liferay portal.

Lets get started. In your Portlet JSP please add enctype="multipart/form-data" to the form tag.

The complete JSP code is provided below for reference

Next lets go to our controller class. Once the form is submitted this class will come into picture.

First we need to get UploadPortletRequest object using the ActionRequest object. This is the object we will use to access all the form elements.

UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(request);

String docTitle = ParamUtil.getString(uploadRequest, "docTitle");
String comments= ParamUtil.getString(uploadRequest, "docComments");

I have used Liferay's ParamUtil which is a helper class. But you can directly get these parameters from the request object using request.getParameter();

Also you can extract file details using

String fileName = uploadRequest.getFileName("documentFile");
InputStream inputStream = uploadRequest.getFileAsStream("documentFile");

That's it.

Thursday, 10 April 2014

Understanding and using the Liferay Document Library - Part 2

In Part 1 of this blog post we saw some basic concepts around how document library can be used, also the database side of it like the tables being used and also the file structure.

In this post I will show you how to upload a document using Liferay's  document library API.

To get started create a MVC Portlet.

Understanding and using the Liferay Document Library - Part 1

In this two part blog post I will try to explain how to use the Liferay Document Library to store and manage your documents.

I will be using Liferay version 6.2 CE to illustrate this. Also I won't go into the meta-data details for the documents, for that you can refer to the user guide.

In the first part I will discuss some concepts related to the Document Library. Like the tables being used etc.

In the second part I will show you how to use the API from a Portlet. If you want to directly see that then here is the link.