:::: MENU ::::

MVC Portlet Development : MVC Framework and AlloyUI in Liferay

What we have done so far ,

Eclipse Installation

Directory Structure

Service Builder – I

Service Builder – II

and continuing to the last part . The MVC Framework and Alloy UI

Every Portlet on a portal page , will have a different render and request cycle.

In servlet we either implement a doGet or a doPost method which handle the response and the request in the same cycle. But here in the Portlet specification jsr-286 , the request and rendering or response is handled separately.

In the Portlet cycle , we have two main methods processAction and render.

processAction handles all the requests and render handles the response.
When the portlet is loaded for the first time , render is called to load the default view lets say a form.When you fill the form and send it across processAction will be called to get all the form data.Once the processAction is executed you can specify a jsp page where the next event has to be handlded. By default it will go to the home page.

But in the MVCPorrlet interface , all these things have been abstracted for us. We donot need to implement any of these render or processAction methods.

In portlet.xml we specified view-jsp as n initial parameter.This is nothing but the location of the default page that loads when the portlet is loaded for the first time or whenever no action is called.

In MVC Portlet , there is a simple way of sending a request and rendering the response.

Below is the code of a JSP file and its corresponding MVC portlet.

In Portlet , we cannot create our own links, the way we do it in servlets . We need to create URLs to submit a form or to perform some action.

The above code , maps the to the function

in the BooksPortlet class.

The name in actionURL tag is the name of the function that is implemented in the portlet class. The var is just a variable holding the link.

So while creating a form , we specify it in the following manner .

Just like actionURL , we also have renderURL .

It basically renders a jsp or an HTML page.

For rendering any JSP , MVCPortlet framework , has the above syntax.
For rendering after completing an action , we have

Calls to these functions , are followed by execution of the

function internally.


As you have seen in the BooksPortlet , we have called two functions ,

This is a standard procedure followed by Liferay , to reduce concentrating all the code in one class itself. Like common , it follows more out of practise and common sense. So here , are the two classes , BooksActionUtil.class and BooksValidator.class



themeDisplay is an object containing all the information about the page, its layout, about the user whether he is logged in or not , certain fixed urls like create account , sign in etc. from themeDisplay we can get information about the company,group,user the particular page is associated with. It’s a very important object.

Here is the documentation of the ThemeDisplay Object and its functions.

Here is the Screen Shot of the portlet that we have created.


The date picker object Is very simple to implement. Here is the implementation code.

For the date picker , it is necessary to provide the Model and the bean attributes to the input tag.
In the src/META-INF folder , we have a n xml file where we can set restrictions on the datatypes

We can also restrict the lenth of certain fields using

For more info on model-hints , take a look at the liferay source code ,
portal-impl/src/META-INF/portal-modelt-hints.xml file.

NOTE : While using the date field , the name attribute of the input tage should match with the name attribute of the field tag in portlet-model-hint.

ParamUtil and PortalUtil.

ParamUtil is a utility class provided by liferay to extract the parameters from the query strings with a lot of added functionality.
For Example :

Here the getString method is having 3 parameters, request object ,the parameter name , and the default parameter if in case there is an error in the connection or the session is timed out.

ParamUtil Documentation .

PortalUtil is also a utility class having some portal related functions

Liferay Also provides a Validator class , which we can use to validate all predefined java primitives and objects.
Life email address,phonenumber , street address , null check etc.
Validator Documentation

Liferay-Search Container

Liferay provides yet another awesome feature of generating a tabular container , with navigation capabilities.
Its also pretty simple to implement. You just needs the list of Object that needs to be displayed.That object can either be Model class or our Own bean class.

In the tag , we first populate the list . It counts the number of elements.

this tag , is used to display the all the information , But we must make sure to give the correct class name and the primary key

Note : Make sure you specify your “className”, “keyProperty” name exactly the way you have written in service.xml, It is case-sensitive , and the “modelVar” is just a variable name, You can name it whatever you want just make sure that name doesnt repeat throughout the entire jsp document

Note : Make sure that the property matches the exact property name given in service.xml

You might come across a situation where the data in your column is not matching the UI requirement , Like for Example , you store the date in 1970,11,11 and now you want to format this date before you put it up on search-container , how to go about that ?

Simple , Just create a new Class , and just to follow proper naming convention , post-fix the class name with “Bean”
Then create instance variables , of the class same as that in service.xml , you can also give them different names
For Example , for the books portlet ,

then refer modelClass=com.package.name.BooksBean and the keyProperty=bookId or whatever you have chosen in your beanClass.

Also while populating the List donot forget to map each property of Bean to the Actual Class

More on Search Container

Liferay-Permission Checker

Checking permission in liferay is just a matter of calling a function .

permissionChecker.hasPermission(groupId, name,bookId,"DELETE") ;

This function , is given the groupId , the name of the class , the primary key of the class and the type of Action supported.
We have defined all this in the default.xml file under the resource-actions folder.
The above permissionChecker , simply passes on these parameters and checks it against the permissions given to the particular user . If the user has permission it will return true , else false.
We have used the permission checker to toggle the Delete functionality for different users . Any user having role for which delete functionality has been granted permission . will see the delete icon , else wont.
Here is a screen shot displaying the permissionChecker in action , with 2 images of the portlet on before log-in and one after log-in.

Pre-Login .


PermissionChecker API

Liferay Messages

SessionMessages and SessionErrors , are two classes which ease out sending out messages to the users or while debugging.
Few Uses of the liferay-error :

The message attribute contains the key to the key-value pair store in the Language.properties file.

Language.properties :

If you click on Submit with all the fields empty , it will show you the above messages.

Some More Useful Links :

Liferay-UI TagLib :

Liferay Freak :

Minesweeper Portlet Game

Main Page of Development Articles in Liferay

From DB to simple UI

Liferay MVC Framework :

LinkLiferays Permissioning System :

Portal Properties Liferay 6.0.5

Alloy UI Forms :

Alloy-UI Scripting basics :

Alloy-ui Working with widgets :

Alloy-ui Working with Ajax :

and plug-ins :


  • Reply DanZ Tensai |

    hi There I’ve followed all of your instruction but all I got is error when deploying…and after I’m download your book-portlet it’s still error the same error

    03:11:47,536 ERROR [HotDeployUtil:112] com.liferay.portal.kernel.deploy.hot.HotDeployException: Error registering portlets for Books-portlet
    com.liferay.portal.kernel.deploy.hot.HotDeployException: Error registering portlets for Books-portlet
    at com.liferay.portal.kernel.deploy.hot.BaseHotDeployListener.throwHotDeployException(BaseHotDeployListener.java:45)
    at com.liferay.portal.deploy.hot.PortletHotDeployListener.invokeDeploy(PortletHotDeployListener.java:104)
    at com.liferay.portal.kernel.deploy.hot.HotDeployUtil._doFireDeployEvent(HotDeployUtil.java:109)
    at com.liferay.portal.kernel.deploy.hot.HotDeployUtil._fireDeployEvent(HotDeployUtil.java:182)
    at com.liferay.portal.kernel.deploy.hot.HotDeployUtil.fireDeployEvent(HotDeployUtil.java:38)
    at com.liferay.portal.kernel.servlet.PortletContextListener.doPortalInit(PortletContextListener.java:99)
    at com.liferay.portal.kernel.util.BasePortalLifecycle.portalInit(BasePortalLifecycle.java:42)
    at com.liferay.portal.kernel.util.PortalLifecycleUtil.register(PortalLifecycleUtil.java:52)
    at com.liferay.portal.kernel.util.BasePortalLifecycle.registerPortalLifecycle(BasePortalLifecycle.java:50)
    at com.liferay.portal.kernel.servlet.PortletContextListener.contextInitialized(PortletContextListener.java:55)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3972)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4467)
    at org.apache.catalina.startup.HostConfig.checkResources(HostConfig.java:1244)
    at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1342)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:303)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1337)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1601)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1610)

  • Reply DanZ Tensai |

    hi there now I get This Error
    05:53:40,014 ERROR [PortletRequestDispatcherImpl:107] org.apache.jasper.JasperException: /jsps/view.jsp(1,1) Failed to load or instantiate TagLibraryValidator class: org.apache.taglibs.standard.tlv.JstlCoreTLV
    org.apache.jasper.JasperException: /jsps/view.jsp(1,1) Failed to load or instantiate TagLibraryValidator class: org.apache.taglibs.standard.tlv.JstlCoreTLV
    at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
    at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
    at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:88)

    please i need ur help

  • Reply Sunny |

    Hi ,
    I am using search container to search the values its working , but now my need is that .in my first column text i want to link another page ,like when someone click on that text the new popup window will open in editable form …can you please help me for this …

  • Reply DanZ Tensai |

    hi there sunny maybe I can help u
    …maybe u can use this syntax on your jsp page

    maybe u can use that?

    and can u help me?did u download the book-portlet from this site?can u run it??
    I Can’t run it…maybe u can send ur book portlet to my email???THank’s

  • Reply Roman |

    Hi really amazing page…you can help me? i have one problem: ClassUtil.getCounts() dont work or dont refresh when i add queery to databases here is my code on jsp:

    No of Players in Database :
    < %
    out.println(HracLocalServiceUtil.getHracsCount()); /this is Util method
    out.println(HracLocalServiceUtil.getAllCount()); /this is my method

    when i started page this work but when i added to player dont refresh number in page … sry for language thank you

  • Reply ابوعبدالرحمن |

    hi i have a problem when i click in the button add book :
    com.liferay.portal.ResourceActionsException: There are no actions associated with the resource com.Books.database.model.Books
    at com.liferay.portal.service.impl.ResourceLocalServiceImpl.validate(ResourceLocalServiceImpl.java:927)

  • Reply KIRAN KAUR |

    can anybody please help me to create a liferay portlet in which we can use/call the code of spring mvc using hibernate annotaions (means we are able to call directly @request mapping url of controller)with any good example/tutorial.

  • Reply Inderjeet |

    When I click on submit button I get the following error

    com.liferay.portal.NoSuchResourceActionException: com.books.database.model.Books#DELETE
    at com.liferay.portal.service.impl.ResourceActionLocalServiceImpl.getResourceAction(ResourceActionLocalServiceImpl.java:80)
    at sun.reflect.GeneratedMethodAccessor200.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

    Please help me to jolt out the problem. It will be greatly appriciated.

So, what do you think ?