Creating custom Liferay MVC portlet

In this article, we will see how to write custom Liferay MVC portlet. Liferay MVC is a lightweight framework provided by liferay to create JSR-168/286 compatible portlets. For simplicity, we will display the string stored in request attribute.

Create Liferay MVC Portlet

First Create Liferay Portlet with project name as custom-liferaymvc and wizard will append -portlet at the end. This looks like below screenshot.

Creating custom Liferay MVC portlet - Project structure

Extending Liferay MVC Portlet

Liferay MVC portlet is ready. Our goal is to customize Liferay MVC portlet. We will make necessary changes in Liferay MVC portlet to develop our custom Liferay MVC portlet. Open portlet.xml file where the <portlet-class> entry looks like this.

We will point our custom portlet in <portlet-class> attribute. Our custom class extends LiferayMVC class. After this change the above entry will looks like below snippet.

Create the package com.companyname.portlet and java class CustomMVCPortlet in source folder.CustomMVCPortlet  extends MVCPortlet class. At this moment, project structure looks like below screenshot.

Creating custom Liferay MVC portlet - Adding custom Portlet class

Portlet class hierarchy

We are extending MVCPortlet provided by liferay. Underlying class hierarchy is as per below screenshot.

Portlet_Class_Heirarchy

  • Portlet interface define core abstract methods and it is on top in Portlet API stack. All portlets implements this interface directly or indirectly (By extending class that implements this interface)
  • Portlet interface defines init, destroy, render and processAction methods which represents init, destroy, render and action phase of portlet respectively.
  • Apart from Portlet interface, following 3 interfaces are part of portlet API
    • EventPortlet – This interface defines processEvent method. This method represent event phase of portlet and was added in JSR-268 (Portlet Specification 2.0)
    • PortletConfig – This interface defines
    • ResourceServingPortlet – This interface defines serveResource method. This method represent serve resource phase of portlet and was added in JSR-268 (Portlet Specification 2.0)
  • GenericPortlet implements all above interfaces and provides default functionality. GenericPortlet class and these interfaces are part of portlet API and available in portlet.jar (at <Liferay-bundle>/tomcat/lib/ext path)
  • LiferayPortlet extends GenericPortlet and provides additional methods. LiferayPortlet is available in portal-service.jar (at <Liferay-bundle>/tomcat/lib/ext path)
  • MVCPortlet is defined by Liferay. It extends LiferayPortlet and provides MVC architecture. MVCPortlet is available in util-bridges.jar (at <Liferay-bundle>/tomcat/webapps/ROOT/WEB-INF/lib/ path)
  • CustomMVCPortlet extends MVCPorrtlet. This is our custom Liferay MVC portlet.

Before moving further, I would like to share some brief characteristics of portlet.

1) Mode :- Portlet has various modes like View,Edit and Help. Portlet renders its output inView mode.
2) Phase:- Portlet has various phases like Render phase, Action phase, Serve Resource phase, Event phase etc.
 
On one page, we can place more than one portlets. On refreshing the page, all portlet’s render phase will be called by portal.

At a time, only one portlet’s Action phase is called on particular page. Action phase is called before Render phase of all portlets. However which portlet’s Render phase is called first is not predictable.

Render phase of the portlet is called soon after Action phase of that portlet is finished.You may wonder how we can call Render / Action phase of portlet. Well we have to create respective URLs on JSP with the help of Liferay TLD. On clicking these URLs, respective phase of the portlet will be called.

In Portlet Render method represents Render phase and Action method represents Action phase.

We will first create Render method that will represent Render phase of the portlet. We are overriding  render method which is defined in GenericPortlet

don’t forget to make call to super.render(request, response) at the end of this method to call render() method defined in GenericPortlet for further processing. Without calling super.render, render method will not work properly.
You can notice that, view.jsp is created at root level by default (under docroot folder). You can change its location.

portlet.xml defines page flow of portlet as init parameter. Ex. view.jsp is give as an init parameter of the portlet as below code snippet


Once render method completes, Portlet will call jsp defined in this init parameter.If you change the location of view.jsp then you have to update the location in this init parameter. For example if we place view.jsp under jsp folder (under root folder) then its relative path needs to be defined in value attribute of <init-param> (/jsp/view.jsp).

I followed above example and created jsp folder under root(docroot) folder and placed view.jsp in it. It looks like below screenshot.
Creating custom Liferay MVC portlet - define view.jspWe need to update the location in portlet.xml file also. After updates, It looks like below snippet.

I have just shown first few line of portlet.xml. I updated the location of view.jsp in <init-param>. The rest content of portlet.xml  will remain same.

Passing data from action to render method

Let’s see how render() method works. Open view.jsp file and remove the default text and put some custom text. For example, I have put “This is custom Liferay MVC portlet” and deploy the portlet.

Access the server with http://localhost:8080 and place this portlet on page. You can create new page.


Note:- To know how to build,deploy and place portlet on page, please refer my previous blog 
Create Liferay Portlet

After you deploy the portlet, you will notice that the text that you written in view.jsp  is displayed.


Now we will write action method and also will show how to call this Action method.

Add following code to CustomMVCPortlet class

Explanation:- 

  • @ProcessAction annotation is used to map Action method with key. Key is defined by name attribute (Ex. name=”addName” ). This key is used to create actionURL in JSP.
  • Action method can be called by creating actionURL in JSP. We can have more than one Action methods in portlet. 
  • To call particular Action method, actionURL needs to be created in JSP with same key that we gave to Action method (in name attribute of @ProcessAction annotation). 
  • The name of Action method can be anything. 
  • Its not necessary the name of Action method and Key of @ProcessAction are same. But just for simplicity I have used the same name. (For name of Action method and Key).
  • In the body of this Action method, we just set userName attribute in request scope.
  • Also notice that, except setting attribute, there are not code exist in this Action method. Portal will call Render method after finishing Action method.
  • So when this action method is called by actionURL from view.jsp , the flow will be like Action method –> Default Render method –>View.jsp again.

Refer below code snippet to create ActionURL. Link is created with this actionURL to call Action method. (Remove the default text that we have entered)


Explanation:- 

  • Portlet tld (<portlet:actionURL>) is used to create actionURL.
  • name attribute of actionURL should be match with the name attribute of @ProcessAction annotation (Key of the Action method).
  • var attribute will be used to refer this actionURL. It is added as pageScope variable in JSP. Notice that we have used this variable in href with EL.
  • You can create more than one Action url with different <portlet:actionURL> tag. The name attribute should be unique. Each actionURL defined in JSP will be tagged to unique Action method in our customMVC class by matching name attribute. (name attribute in <portlet:actionURL> and name attribute in @ProcessAction annotation in customMVC class).
  • We have written the first line, which shows the userName that we are storing in request scope in Action method.

After deploying the portlet, it renders like below screenshot.

Creating custom Liferay MVC portlet - portlet rendering

You can observe that, first time there is no userName displayed. Click on AddName link and it looks like below screenshot. 

 

Creating custom Liferay MVC portlet - calling action to render method
You can notice that, the User name Nilang which we set in Action method is displayed. It means whatever attribute(in request) we set in Action method, will be available in Render method and also in view.jsp file.
 
Also notice that the success message shown at the top saying  Your request processed successfully. This message is automatically added by MVCPortlet.
 
Let’s see advance use of Action method. In this case,we will simply replace link with textbox and submit button. So Whatever user enter the name, it will be shown back so it will be more dynamic than first approach where we are setting hardcode attribute in Action method.

Add following changes in view.jsp file 

As you can observe that I have removed the link and added text box and submit button surrounded by <form> element and given actionURL to action attribute of this form element.
Note:- Please make sure whenever you submitting with form with actionURL you need to set method as POST. Otherwise action method will not work properly.

In action method, we will read parameter from request and will set to request scope. After this change, the action method will look as below.

We are taking userName from request. I have used ParamUtil (utility class provided by Liferay) to get the request parameter. The last method parameter(of ParamUtil.get) is a default value in case if request parameter (mentioned in second position just after actionRequest in get method of ParamUtil) is not found.

Then I simply set this variable request scope. So this becomes more dynamic then the first approach.


Now deploy the portlet and refresh the page where we placed this portlet. view.jsp will look like 

Creating custom Liferay MVC portlet - passing parameter

Now enter any user name say Joe Bloggs and click on Submit button. The page get refresh and view.jsp will show the entered user name as per below screenshot.
Creating custom Liferay MVC portlet - reading request parameter from action to render

You can put more complex logic in action method. Also you can have more than one action method in controller class. To understand it properly, try some hands-on with multiple actions method calling with different actionURL from JSP.
To know further about render and action phases / lifecycle you can refer this link

Summing up

  • Liferay MVC is lightweight framework provided by Liferay to create JSR-168/286 compatible framework.
  • To provide custom implementation, we can defined our own portlet class that extends LiferayMVC class provided by Liferay.
  • In this custom Liferay MVC portlet, we can define our own render logic by extending render() method. We also can defined multiple action methods.
  • This way we can define our own custom flow from action to render method.

Download Source Code

Download Source

 

Share This Post

66 Comments - Write a Comment

  1. Hii nilang your example is really helpful to me but can you tell me one thing when i trying to build multiplication portlet it is showing me following stacktrace

    SEVERE: Servlet Dynamic Resource Servlet threw unload() exception
    javax.servlet.ServletException: Servlet.destroy() for servlet Dynamic Resource Servlet threw exception
    at org.apache.catalina.core.StandardWrapper.unload(StandardWrapper.java:1503)
    at org.apache.catalina.core.StandardWrapper.stopInternal(StandardWrapper.java:1843)
    at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
    at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5614)
    at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
    at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3947)
    at org.apache.catalina.startup.HostConfig.checkResources(HostConfig.java:1270)
    at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1439)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:315)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
    at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1374)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1530)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1540)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1519)
    at java.lang.Thread.run(Thread.java:722)
    Caused by: java.lang.NullPointerException
    at com.liferay.portal.kernel.servlet.PortalClassLoaderServlet.doPortalDestroy(PortalClassLoaderServlet.java:115)
    at com.liferay.portal.kernel.servlet.PortalClassLoaderServlet.portalDestroy(PortalClassLoaderServlet.java:54)
    at com.liferay.portal.kernel.servlet.PortalClassLoaderServlet.destroy(PortalClassLoaderServlet.java:40)
    at org.apache.catalina.core.StandardWrapper.unload(StandardWrapper.java:1482)
    … 15 more
    Can you help me out of this ??

    Reply
    1. Hi Jeet

      Thanks for appreciation and welcome to Tech blog. The example I attached is of liferay 6.0. I tried same and build for liferay 6.1 sdk and for me it’s compiled without any error. You can do following 2 things

      1) You need to update DTD for liferay-portlet.xml and liferay-display.xml files from 6.0 to 6.1 (or 6.2 if you are using Liferay 6.2)
      2) Instead of directly copying my example, you can create sample portlet project and then only copy the code.

      I am not sure, which liferay version you are using. If you are using liferay 6.2, you may need to check for any compilation error. I will try to compiler it against Liferay 6.2 and let you know if find any issue. Meanwhile you can check by following above two options.

      Feel free to ask questions / give feedback.

      Regards
      Nilang

      Reply
    1. Hi Navabrindit Solution,

      Thanks for appreciation and welcome to Tech blog. Feel free to ask questions / give suggestions. Also join this blog with facebook and google+ for latest blogs

      Regards
      Nilang

      Reply
  2. Hi Sandeep,

    Welcome to Tech blog. Can you please try the source code which I have attached here. If that works for you, then you can compare your code with it side by side and you will get where you did mistake.

    Feel free to give suggestions / ask questions.

    Regards
    Nilang

    Reply
    1. hallo!

      it doesn’t work on LR 6.2

      ParamUtil.get(actionRequest, “userName”, StringPool.BLANK) == NULL

      I fix this with
      UploadPortletRequest uploadPortletRequest = PortalUtil.getUploadPortletRequest(actionRequest);
      String userName = ParamUtil.getString(uploadPortletRequest, “userName”);

      but
      actionRequest.setAttribute(“userName”, “Kaboom”);

      return nothing
      User Name is : ${userName}
      is empty…

      how can i fix this?

      Reply
    2. Hi Elderov Ali,

      Liferay had restricted reading parameter with portlet name space pre-pended by default since 6.2 onward. Means any parameter whose name is not having portlet name space, liferay will not read it by default.

      To overcome this, there are two work around.

      1) either you can append portlet name space to each parameter name For example if you want to read “Username” parameter, you can prepend portlet name space like like <input type=”text” name=”<portlet:namespace>UserName” value=”” />

      2) By default this behavior is enable. You can disable this by adding
      <requires-namespaced-parameters>false</requires-namespaced-parameters>
      add this entry(required-namesace-parameter to false ) just after <instanceable>true</instanceable> in liferay-portlet.xml file.

      Feel free to ask questions / give suggestions

      Regards
      Nilang

      Reply
  3. Hi Nilang.
    I´ve followed your great post but I´ve got a problem.
    It´s the same problem that Veronica Medeiros told you on March the 3rd 2014.

    You gave her a solution by changing a param on liferay-portlet.xml file but I don´t find the param you refer because any of them have a value true or false.

    Thank you

    Reply
    1. Hi Pedro Conde,
      Welcome to Tech blog and thanks for writing here. I assume that you are using liferay 6.2. What I feel is that Vernocia not getting the parameter he is passing from JSP. The reason is, from liferay 6.2 version, liferay mandate to read the parameter with portlet name space. To give some brief about portlet name space, its unique string value for each portlet which will be used to associate variable names in specific portlet to avoid name conflict of variable across two portlet (if variable name is same across portlet).

      However we can override this behavior by setting one value to your liferay-portlet.xml file as below

      false

      this can be place after true elemenet.

      Try this and let me know if this work for you.

      Regards
      Nilang

      Reply
    2. Hi Nilang.

      I tried to change the value you told me in my liferay-portlet.xml but this file doesn´t have any param whith true or false value inside. So I don´t know what I have to do and everything I make has a mistake as consecuence.

      Thanks

      Reply
    3. Hi Pedro,

      Actually, it will not be there by default in liferay-portlet.xml. You have to define it explicitly. I thing, I paste the pure xml, so it get vanished. Let me give it again by html decoding. You have to place following.

      <requires-namespaced-parameters>false</requires-namespaced-parameters>

      This should be after <instanceable>true</instanceable>, since its xml so order will matter.

      Let me know if this work for you. You are on right way, so just set this in liferay-portlet.xml and check. let me know if you get success. Feel free to ask questions.

      Regards
      Nilang

      Reply
  4. Hi Nilang – Thank you for the response. The JSP page is on same sub-net, within the network (will not be an external call). Although JSP is not on the same server where LR is installed, its on the same sub-net albeit on a different server., is it possible to call that JSP then? Lets say if I am able I load the JSP, and submit the form elements and receive XML response, what modules do you recommend I use to handle the XML to HTML conversion using XSLT? Do you have any suggestions?

    Thanks
    Aparna

    Reply
  5. Hi Nilang

    Thank you for your blog, I find it very useful. Can you please provide an approach I need to take to handle this task explained below, can you please let me know the best approach to handle it in LR, so I may follow the broad guidelines you recommend. I need to write a custom portlet, that can call a JSP file from a different server (JSP does not reside on the same server where LR is installed), portlet needs to display the contents of that JSP (The JSP page has a form with a submit button). Now when this form is submitted, it responds back with XML content. The portlet needs to take this XML response, apply XSLT which will convert to HTML, this HTML will need to be rendered on this portlet. Can you please give me an approach to take? are there any liferay modules that will come of help in handling this?

    Reply
    1. Hi Arpana,

      First of all Welcome to Techblog and thanks for appreciation.

      Its not possible for portlet to call JSP from other domain. Just consider liferay as web application and ask question like, will it be possible to call any J2ee web application to call JSP from different domain ? If its possible, Atleast I haven’t heard this way.

      What you can do it, you can get XML response from web service. For this, from other side, it should expose web service and you can make web service call from portlet and get your response (in form of xml) and then translate it to html and render.

      Let me know if this works for you

      Regards
      Nilang

      Reply
    1. Hi Veronica,

      Welcome to Techblog and thanks for appreciation. Your problem is that you are following liferay 6.1 code in liferay 6.2. Starting 6.2 liferay had put mandatory practice by which you have to use portlet namespace while reading parameter from request scope.

      There is one attribute in liferay-portlet.xml. I forget the exact name but it its about namespace. Default value is true. You have to set it false and then try my code. It should work.

      Let me know if this resolve your problem.

      Regards
      Nilang

      Reply
  6. Liferay portalet6.1 [ActionURLTag:71] Render response is null because this tag is not being called within the context of a portlet
    I am using Liferay portalet6.1. When i am running my application every time, getting ERROR i.e [ActionURLTag:71] Render response is null because this tag is not being called within the context of a portlet

    Reply
  7. Hi Nilang,
    Can u tell me how can we retrieve and insert data from liferay tables. Is there any direct connection to liferay database or I should create new connection?

    Sonal

    Reply
  8. Hi Nilang,

    Access problem has resolved..

    Problem Brief: By default remote access to the MySQL database server is disabled for security reasons. so after un-dumping/restore database to mysql there was a problem of access denied for the user and the ip address of the machine on which mysql is running

    Resolution:
    step 1: Edit the /etc/my.cnf and add parameter ie

    bind-address=YOUR-SERVER-IP

    step 2: restart mysql server

    step 3: go inside mysql ie mysql -u root -p password

    step 4: run this command to allow permission:

    GRANT ALL PRIVILEGES ON *.* TO ‘username’@’machine ip address’ IDENTIFIED BY ‘password’ WITH GRANT OPTION;

    Thanks Nilang for your time and inputs..

    Reply
  9. Hi Nilang,
    I am facing a problem while starting liferay tomcat server
    in catalina.out logs are some what like this:-

    ERROR [DialectDetector:116] org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Access denied for user ‘root’@’NDC-LVA-NMA01’ (using password: YES))
    org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Access denied for user ‘root’@’NDC-LVA-NMA01’ (using password: YES))

    10:46:39,641 ERROR [PortalHibernateConfiguration:95] java.lang.RuntimeException: No dialect found
    java.lang.RuntimeException: No dialect found

    10:46:39,827 ERROR [ContextLoader:220] Context initialization failed
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘serviceAdvice’ defined in class path resource [META-INF/base-spring.xml]: Cannot resolve reference to bean ‘asyncAdvice’ while setting bean property ‘nextMethodInterceptor’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘asyncAdvice’ defined in class path resource [META-INF/base-spring.xml]: Cannot resolve reference to bean ‘threadLocalCacheAdvice’ while setting bean property ‘nextMethodInterceptor’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘threadLocalCacheAdvice’ defined in class path resource [META-INF/base-spring.xml]: Cannot resolve reference to bean ‘bufferedIncrementAdvice’ while setting bean property ‘nextMethodInterceptor’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘bufferedIncrementAdvice’ defined in class path resource [META-INF/base-spring.xml]: Cannot resolve reference to bean ‘transactionAdvice’ while setting bean property ‘nextMethodInterceptor’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘transactionAdvice’ defined in class path resource [META-INF/base-spring.xml]: Cannot resolve reference to bean ‘liferayTransactionManager’ while setting bean property ‘transactionManager’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘liferayTransactionManager’ defined in class path resource [META-INF/hibernate-spring.xml]: Cannot resolve reference to bean ‘liferayHibernateSessionFactory’ while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘liferayHibernateSessionFactory’ defined in class path resource [META-INF/hibernate-spring.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException

    pls revert asap

    Reply
  10. Hi Nilang,
    I know the action response in this MVCPortlet extension, however, can you clear up exactly where in this class this spelled out such that
    “Your Request has been processed” rendering is implemented and why does it display embeded in my view.jsp page?? I know you tried to explain it as the default response but where exactly is that?
    Currently I find this to be a mystery!
    Also I am seeing multiple entries after deployment in the add section under Sample Why only two no matter how many portlets I deploy??

    On another note – How can I remove title bars from my portlets – Obviously in production I will not want to see title bars??

    Reply
    1. Hi Perry,

      First of thanks for appreciation and welcome to tech-blog. The answer of your second question is as below

      Login with Admin.
      Tick mark the checkbox called “Toggle Edit Controls” from dockbar (at top).
      click on option icon(tool like image) at top right side of portlet and click on Look & Feel
      In first tab – portlet configuraiton, just tick mark “Use Custom Title” check box.
      Once you do this, the portlet title text box will be enable. Just remove all content in it and click on save button.

      You will observe that the portlet title is no longer appear.

      For the category sample…. In Liferay each portlet can be defined under certain category. Open liferay-display.xml file and give the category name.

      For your first question, I will check and give you exact answer.

      Feel free to ask questions / give suggestions.

      Regards
      Nilang

      Reply
  11. Hi Nilang.

    I created a custom portlet as per the given steps above. I can see the created portlet in the “Add more” dropdown in the IDE. But when I add it to a page only loading wheel appears but the portlet does not add. May be there is something I have missed.

    I can see the following warnings in the catalina log:

    eploying configuration descriptor C:Usersshs_qaDownloadsliferay-portal-6.1.1-ce-ga2tomcat-7.0.27confCatalinalocalhostcustom-liferaymvc-portlet.xml
    23 Jul, 2013 9:46:55 AM org.apache.catalina.startup.HostConfig deployDescriptor
    WARNING: A docBase C:Usersshs_qaDownloadsliferay-portal-6.1.1-ce-ga2tomcat-7.0.27webappscustom-liferaymvc-portlet inside the host appBase has been specified, and will be ignored
    23 Jul, 2013 9:46:55 AM org.apache.catalina.startup.SetContextPropertiesRule begin
    WARNING: [SetContextPropertiesRule]{Context} Setting property ‘source’ to ‘org.eclipse.jst.jee.server:custom-liferaymvc-portlet’ did not find a matching property.

    Reply
  12. Hi,
    I am new to Liferay How to open view page directly using URL.
    When ever I run my project I am getting default liferay pages not our view.jsp.
    Please help on this. I want display view.jsp page content.

    Reply
    1. Hi Dhaval,

      Sorry for late responding. You can set super.viewJSP=”Path of your custom JSP” just above the line super.doView() or super.render() method call.

      By default, it will call view.jsp under docroot folder. If you want to show you custom jsp, you need to set super.viewJSP variable with the path of your custom jsp.

      Let me know if this is not works for you.

      Regards
      Nilang

      Reply
  13. hi Nilang..
    i’m working on a portlet that contains a combobox..the aim is to get the selected item of the combobox and compare it to values in a MySQL database..i want to know the syntax to implement that..thanks

    Reply
  14. Hi Nilang,How r u ?

    Nilang i m facing a problem while hosting liferay server at production level

    problem : After deployment and startup of liferay server 6.0.6 on production server(linux – redhat ) logs are not coming in catalina.out file .

    only below few lines are coming at catalina.out file:-

    java.lang.ClassNotFoundException: org.apache.catalina.startup.Catalina
    at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
    at org.apache.catalina.startup.Bootstrap.init(Bootstrap.java:216)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:391)

    options i have tried are:

    1. accessing liferay server by entering URL at browser tab- no output
    2. checked catalina.out logs mentioned above

    any ideas where is the problem.

    Thanks
    Vipin

    Reply
  15. Hi Nilang,

    I am just starting on liferay, thanks for the excellent tutorials. I followed most of them and it works. Now, I created my portlet with a bunch of table contained in a div tag. They overflow on the page and go beyond my portlet. I do not want to set a default size as eventually this portlet will retrieve data from the database. Any quick pointers on how to set the size? I tried defining the styles for my container and other elements in main.css and also within the portlet itself, but, nothing works. Appreciate any suggestions.

    Thanks again,
    Suma.

    Reply
    1. Hi Suma,

      Welcome to Tech blog and thanks for appreciation. You can fix the height of the parent DIV and set its style as overflow:auto or overflow:scroll. To make this work, you must have to give fix height for parent DIV.

      Let me know if this not works for you.

      Regards
      Nilang

      Reply
  16. Hi
    you haven`t mentioned the Application context xml file here :). Could you please explain why havent you mentioned this xml file here.
    Could you also let me know a bit more about the purpose of using Application context xml file in a liferay project.
    I also appreciate If you could share the knowledge regarding liferay-hook.xml file.

    Reply
    1. Hi Joga,

      You are mixing two things. I assume that you are asking question that why I haven’t put the application context file for Liferay MVC Portlet (Because you post this comment in this blog). Application context file will generally be there for spring. In simple terms, its the configuration file for spring from where spring will do various process while loading the web application context.

      In Liferay we can develop portlet in various framework like

      Liferay MVC (out of the box provided by liferay)
      Spring MVC (The one which I gave my last reply)
      ZK Portlet
      Struts 1 Portlet
      Struts 2 Portlet
      JSF Portlet

      etc.

      Application context file is required if you are developing your portlet with Spring in Liferay.

      Hope this clear your doubts.

      Reg. liferay-hook.xml, its totally different kind of plugin. Its used to do following things.

      1) Override existing Liferay JSP files
      2) Adding / modifying language property
      3) Extending Service class (From 6.1 onwards)
      4) Adding certain listeners like Pre action, post action etc
      and lot other. I am planning to write separate blog on hook in liferay. For now, you can refere liferay wiki pages for hook.

      Let me know if you need more help

      Regards
      Nilang

      Reply
    2. Hi Nilang,

      Thank you once again for giving me a fast and appropriate answer. I though Liferay MVC, Spring MVC and its features are same. I realized now I am wrong :(. I will keep that in mind and continue. All the best for your future blogs.

      Cheers

      Reply
    3. Hi Joga,
      Liferay is like big ocean. Even I some times feel that my knowledge is not enough. But any one can learn learn it by dedication. I would suggest you to start its admin portion. Once you are familiar with admin portion, you can start development section.

      Feel free to ask any questions any time. Because I believe that knowledge can only increase by sharing it.

      Regard
      Nilang

      Reply
  17. Hi Vipin,

    First of all Congratulation on successfully getting your portlet works…!! That’s really make me happy.

    You are right, you can still deploy it with direct deploy option. But this option we are using when we deploying the EXT plugin. For all other plugins (portlets,hooks,themes and layouts) we only using ‘deploy’ option.

    You can do following things.

    1) undeploy the portlet (click on un-install from Update Manager – the last option in control panel).
    2) stop the server and delete ‘work’ and ‘temp’ folder under tomcat.
    3) restart the server and also delete the cache of browser and then check with only deploy target.

    After this steps, it should work with only with deploy.

    Regards
    Nilang

    Reply
    1. Hi Nilang,

      Above steps doesnt work for me 🙁
      but i am deploying my portlet by using either of the way that are:

      1) either double click on the ‘direct deploy’ option under ant window.
      2) or right click on build.xml file under portlet-project and
      click on Run As-Ant built..
      after doing either of the above steps my portlet get deployed

      but i afraid that is; may these are not the correct way to deploy portlet and will not generate some problem in future..

      Thanks Nilang
      Take Care 🙂

      Reply
    2. Hi Vipin,
      Just wanted to know which version of eclipse you are using.

      However, when we do right click on Build.xml and click on Run as Ant-Built then it will execute the default target. You can confirm that the default target is ‘deploy’ only. So its still correct way. No problem will occur in future.

      You can deploy by both of these option. So there wont be any issue in future.

      Reply
    3. Hi Nilang,

      I am using Eclipse Version: Helios Service Release 2
      Build id: 20110218-0911

      and i have checked for the option under which ‘i do right click on Build.xml and click on Run as Ant-Built’ my default target is set to ‘direct deploy’ when i changed it to ‘deploy’ again nothing happens my portlet not be able to deploy on server so i again changed it to ‘direct deploy ‘option..

      Reply
    4. Hi Nilang,

      One Good news to tell u 🙂

      my deployment problem has solved..

      Now my portlet get deploy by many ways that were not working earlier.
      -> double click on ‘deploy’ target under ant window working is working fine.
      -> right click on the portlet project -run as -run on server also works

      Root Cause was:
      As u know i have switched from netbeans to eclipse for liferay portlet development so what i did was that while configuring eclipse with liferay tomcat server, i copied liferay tomcat server on another location and set up its path on eclipse-runtime server location(means there are 2 liferay tomcat server one refered by eclispe and other refered by netbeans and both on separate location) so thing is deployment from eclipse doesnt comes into picture reason may be some internal reason like unable to find exact location for deployment..

      Solution:
      what i did is that deleted liferay tomcat server from location where it was referenced by eclipse and set path of liferay tomcat server(that i was used for netbeans) on eclipse . now there is only 1 liferay tomcat server in my system that is currently in used..

      Thanks nilang for every reply 🙂
      Take Care

      Reply
    5. Hi Vipin,

      That’s g8. I appreciated your passion towards finding the solution. Its great characteristic in you.

      Now I feel relax that now you are able to get what you want. I also learn during our conversation .. so thanks to you also.

      As I believe… knowledge will only increase by sharing it… so feel free to ask anything. I will try my best to get the answer.

      Regards
      Nilang.

      Reply
  18. Hi Vipin,
    actually, liferay-portal-6.0.6/deploy is the place from where we can do deployment of all pluging. So the following method will do same job. They will copy the WAR file of plugin into deploy.
    1) If you are not using eclipse, and if you build the portlets with ant ‘clean deploy’ command from COMMAND prompt it will create WAR file in ‘dist’ folder. Once this WAR file is created, and if you place this WAR file into deploy folder, it will deploy that plugin.
    2) If you go to Plugin Installation (Or Update Manager) in control manager ( option in Server section) and upload the WAR file
    3) If you are using the eclipse plugin. pls refer second last screenshot from my previous post http://opensource-techblog.blogspot.in/2012/07/create-liferay-portlet.html , In this case when you click on ‘deploy’ target from Ant window then it will build the WAR file and will deploy it into deploy folder.

    All the above activity will do same job.

    Answer to your question.

    Eclipse provide the options by which if you do any changes then it will do deploy the portlet. But some time its annoying because it will always do build and deploy during when you do the changes, make the system less responsive some time. I will show you all the option and then you can use whatever you feel confortable.

    1) In case if auto deploy(as I mentioned) is not enable, then once you do all your changes just double click on ‘deploy’ target in Ant window (you can refere my previous post ‘Create Liferay Portlet’ for same.

    2) If you want to do auto deployment whenever any changes happene, double click on Server (liferay-tomcat-bundle) in server window at the bottom. Then click on ‘Publishing’ section (upper right corner) and click it to see more options. You will see 3 radio button options. Choose the middle one (Automatically publish when resources change).

    follow these options and let me know if any issues.

    Reply
    1. Hi Nilang,

      First of all a Great Thanks.. for giving time for my problem..

      For the Above 3 options that u mentions for deployment, status are:
      1) first one i didnt tried bz i am creating portlet via eclipse IDE
      2) second one is working fine..
      3) third one i tried it many many times but its giving message on console last line of that is :
      ” deploy:
      [copy] Copying 1 file to F:eclipse-jee-helios-SR2-win32liferay-portal-6.0.6deploy
      BUILD SUCCESSFUL
      Total time: 750 milliseconds “

      -after that my portlet war goes to deploy folder under path ie
      eclipse-jee-helios-SR2-win32liferay-portal-6.0.6deploy

      -but i didnt find my portlet deployed on liferay server 🙁

      For the next 2 options that u mentioned, status are:

      1) this first one is same as option no. 3rd in which u have given me url of your post.

      2)for the second option ie Choose the middle one (Automatically publish when resources change) -this is automaticaly set as u specified.

      at the last status for the day is this:

      now i am able to deployed portlet to liferay server

      way is : as per ur post in which u said “refer second last screenshot from my previous post http://opensource-techblog.blogspot.in/2012/07/create-liferay-portlet.html
      in this screenshot after deploy there is option for ‘direct deploy’
      once i selected it my portlet get deployed and console showing msg ie
      1 portlet get deployed and ready to use

      Many many Thanks Nilang

      Best Regards
      Vipin

      Reply
  19. Hi Vipin,
    Pls let me know what problem you are facing. (ex.compilation or runtime error etc).
    Hovever, Just make sure about the following things.
    1. Is there any Liferay Plugin is available for NetBean. If so then first you have to configure it. (You can still develope liferay mvc portlet without this plugin).
    2.The MVCPortlet is available in util-bridges.jar file. Make sure this jar is there in class file. If not then you can copy from Liferay-TomcatBundletomcat-6.x.xwebappsROOTWEB-INFlib directory. This should solve your problem.

    Reply
    1. Thanks Nilang, for ur rply

      Answer 1: I have already configured netbeans with portalpack_3_0_5_beta_all ie available over net.

      Answer 2: I have added util-bridges.jar file on libraries folder of the current project in netbeans.

      status is:
      1) I am using ur above example of MVCportlet
      2) Before adding util-bridges.jar file it giving me the error for creating a MVCPortlet class in the package but after i added it as i mention earlier error goes off.
      3) now it showing error of RenderRequest,RenderResponse,ActionRequest,ActionResponse for creating their class either in package or in class that we are using
      eg of one of the error is : create class ActionResponse in package com.companyname.portlet or in class CustomMVCPortlet..

      Questions:
      1) If we want to use struts in our web project so is it necessary to use MVCPortlet, can we go for GenericPortlet.

      2) what is the difference bw GenericPortlet & MVCPortlet-which one is best to use for portlet development

      Thanks
      Vipin

      Reply
    2. Hi Vipin,
      Its good that you are able to resolve previously error. Now you are getting error for ActionResponse,request etc. This is because the server library (liferay-tomcat bundle) is still not in the classpath.

      I am not sure much about how to reference it in netbean, but in eclipse we can refer the server library into project. These libraries needs to be present in classpath to make our code compile correct.

      If you not sure how to put the server libraries in class path with netbean, just do the same thing for all Jars under TomcatLiferayBundle–>tomcat-6.0.29–>lib. (including all jars under ext folder under lib folder) the same way you done with util-bridges.jar. Make sure not to place these jars in lib directory of portlat, otherwise your potlet size become too big. Also run time it may create problem as there are two copy of each these jars (one is in portle’s lib and second in tomcat lib). so just make them available on class path.

      Hope this will solve your problem.

      Answer to your questions.

      1) Definately you can use Generic portlet and use struts in your web project. Its not necessary that you always have to use MVCPortlet.

      2) MVCPortlet is child class for LiferayPortlat and LiferayPortlet is child class of GenericPortlet. So in short, MVCPortlat provoide more convenience way that GenericPortlet. IF you want you can still use GenericPotlat.

      Personally I will prefer to use SpringMVCPortlat. I am going to write detail blow on how to write SpringMVCPortlat. Its very easy. Also since its SpringMVCPortlet, we can do tight integration of Spring framework in that.

      If you like this blog then you can join this site so that you can get updates whenever any new things come.

      Reply
    3. Hi Nilang,
      I have created a portlet via plugin sdk and open that into netbeans IDE
      then created a class that extends MVCPortlet and added some jar files in order to avoid errors..

      -now one thing i have noticed is that there is no web.xml file in my project(that should come automatically)
      -my console terminal doesnt show any error in this regard
      -SO do i need to create web.xml manually or is there any other way..

      I am not understanding where i am doing mistake..

      Regards
      Vipin

      Reply
    4. Hi Vipin,

      When we create the portlet with the help of IDE wizard, it should create web.xml in root path. In you case if its not visible in IDE, you may check into filesystem. Because each portlet is separate web application and web application will not be stand on server without web.xml file. so check in the file system.

      You may create another portlet just for testing purpose whether web.xml file display in IDE or not.

      Regards
      Nilang

      Reply
    5. Hi Nilang,

      Actually netbeans IDE is not properly configured with Liferay support,so everytime there is some or another issue comes up with respect to liferay that why i have switched my IDE, now i am using Eclipse and setting/configuring it for Liferay …

      Thanks Nilang..

      Best Regards
      Vipin

      Reply
    6. Hi Nilang,

      I am using eclipse and i have added plugin sdk and liferay server to it
      now i have created a liferay portlet and deployed it to liferay but thing is

      -portlet doesnt deployed (not showing any error except this message ie
      INFO: Deploying web application directory test10-portlet)
      -but its war file comes up in directory : liferay-portal-6.0.6deploy folder
      -then if i took that jar file and deployed it on liferay via control panel-plugin installation-install more portlet-upload file

      by this way my portlet get deployed and showing msg on console ie
      1 portlet for test10-portlet is available for use
      – as per me i think autodeploy of portlet is not set ..

      Question:
      -how can i set autodeploy of portlet in eclipse

      Regards
      Vipin

      Reply
  20. Hi Nilang,

    I am stuck with a doubt related with MVCPortlet
    -> i want to create a java class that will extend MVCPortlet but i am unable to do it in netbeans IDE, by netbeans i am able to create GenericPortlet only,
    Pls tell me know some way to create java class that will extend MVCPortlet

    Thanks & Regards
    Vipin

    Reply

Post Comment