KNOWLEDGEBASE

We pride ourselves on bringing a fresh perspective and effective insight knowledge of each technology.

  • Portlet Filters In Liferay 7 DXP

    Portlet Filters In Liferay 7 DXP

    Portlet Filters In Liferay 7 DXP

    Portlet Filter is used to intercept and manipulate the request and response before it is delivered to the portlet at given life cycle such as action, render and resource

    Environment
    Liferay IDE 3.1.2 GA3
    Liferay CE Portal Tomcat 7 GA4
    JDK 8
    MySql 5.7

    What is Portlet Filter?

    Portlet Filter is used to intercept and manipulate the request and response before it is delivered to the portlet at given life cycle such as action, render and resource

    Types Of Filters For A Liferay Portlet

    Action Filter
    Render Filter
    Resource Filter
    Base Filter

    Which Filter To Use?

    Action Filter : To Intercept only The Action Requests
    Render Filter : To Intercept only The Render Requests
    Resource Filter : To Intercept only The Resource Requests
    Base Filter : To Intercept all the http request comes to your portlet.

    How to Implement Portlet Filter In liferay 7 DXP?


    Step 1 : Create A Module Project for Portlet
    If you want to know how to create a portlet module project in Liferay 7 DXP, please refer my earlier blog, Below is my Portlet Controller Class.


    Step 2 : Create A Portlet Filter Component Class
    You can create Portlet Filter Component Class Using Eclipse, by right clicking on you portlet module project and select select "New Component Class" and Select "Portlet Filter" Component Template, I prefer to create a class manually for now, I Am creating a Class named "MyRenderFilter"

    Step 3 : Component Declaration
    Declare the Class as an OSGI Component Using the Below Code Snippet

    import org.osgi.service.component.annotations.Component;
    import javax.portlet.filter.PortletFilter;
    @Component(immediate = true, 
     property = {
      "javax.portlet.name="+MyPortletKeys.My, 
     },
     service = PortletFilter.class
    )
    
    Note : Make sure you give correct portlet name and service must be PortletFilter.class

    Step 4 : Extend The RenderFilter
    import javax.portlet.filter.RenderFilter;
    public class MyRenderFilter implements RenderFilter{}
    

    Step 5 : Implement Unimplemented Methods of the Parent Class RenderFilter
    public void init();
    public void destroy();
    public void doFilter();
    

    Complete MyRenderFilter.java Code

    Each time when you Hit a Render URL doFilter() method the MyRenderFilter will be triggered.

    Portlet Filter For Action Request


    Similarly You can create the filter for all Action Request By extending ActionFilter Class, as shown below


    Portlet Filter For Resource Request


    For all Resource request you can extend your class with ResourceFilter Class, as shown below

    Servlet Filter In Liferay 7 DXP

    This Filter Intercepts all the requests comes to the portlet, whether it is action, render, resource and it also can be HttpServletRequest , if you want filter all the Http Servlet Request comes to your portlet please use this filter, your filter component just have to extend "BaseFilter" Class, refer the below code

    Note : This BaseFilter Will be Triggered Before all the other filters such as ActionFilter, RenderFilter and ResourceFilter.
    I have created a portlet which can easily make you understand flow of Portlet Filters and Portlet Requests In detail, please download the portlet and deploy to test, it can give more insight into the portlet Filters In Liferay, when you add this portlet to the page init() and doFilter() method will be triggered.


    Source Code


  • Logging In Liferay 7 Using Loggers

    Logging In Liferay 7 Using Loggers

    Logging In Liferay 7 Using Loggers

    Logging In Liferay 7, Liferay Uses Log4J Library for Logging Java Classes, In this blog lets see the Liferay Log Configuration  In Liferay, Liferay Portlet Logging and Log Levels in detail.

    Before Going Into The actual Logging and Loggers in liferay, Lets answer few questions on Logging.

    What is a Log?
    In our Java Code we were using System.out.println("message"); to log (print) the information end error messages, These logs will be printed in the Console and log files, These logs are used to debug the code.

    Why do need a Logging System using Loggers?
    The Logs printed using the System.out.println (sysout) are not more informative, when code snippet System.out.println("message"); gets executed, the only thing it will print on the console screen and log file is message. No other informations.
    There will be NO information about
    1. From Which Class the Log is Generated
    2. At What Time The Log Is Generated
    3. What is the Severity of the message

    If We Use the Loggers to Log the Messages In Java Classes, The log message will holds the information, From Which Class The Log Is Generated, At What Time The Log Is Generated and What is the Severity of the message. Which is not available in sysout.
    Logging In Liferay 7 Using Loggers

    What are the Log Levels Supported By Liferay?
    There are 6 log Levels supported by Liferay, you can decide the level based on the log severity.
    INFO : To Log the useful  information.
    DEBUG : To Log Debug information, use it to debug the code.
    WARN : To Log the warning messages, which are not critical
    ERROR : To Log the error message which blocks a behavior (functionality) being
    FATAL : To Log the messages which can be a severe or vital issue that harms the complete system.
    TRACE : To Log the exception call traces of the code

    Enabling  And Disabling Log Level For A Class
    We can define and configure the Log levels for Each and Every Java Class In the Server Administration section of Control Panel.

    Control Panel  >> Configuration >> Server Administration >> Log Levels

    Liferay 7 Loggers Server Administration

    If we Set The Log Level to ALL, Logs with all Levels will be printed.
    If we Set The Log Level to OFF, No Logs will be printed at all for the specified class.
    If we Set The Log Level to To Info, Only Logs printed using Info Level will be printed, Other Log Levels In Same Class Will not be printed.

    Creating a Logger In Liferay 7
    You can define a Logger for a Class using the below code snippet.
    import com.liferay.portal.kernel.log.LogFactoryUtil;
    private static Log _log = LogFactoryUtil.getLog(LoggerPortlet.class);
    

    To Log The Messages With Different Log Levels.
    _log.info("Use INFO To Log Useful Information");
    _log.warn("Use WARN To Log Warning Message");
    _log.error("Use ERROR To Log Error Message ");
    _log.debug("Use DEBUG To Log Debug Message ");
    _log.fatal("Use FATAL To Log Fatal Message");
    _log.trace("Use TRACE To Log Trace Message of the exception");
    

    How To Check The Log Level of the class
    A Simple _log.info("Use INFO To Log Useful Information"); Will print the message even if you disable(turn OFF) the Log Level for the class in the server administration. As A Best Practice, we must check the Log Level before Logging a message in that level.
    if(_log.isInfoEnabled()){
     _log.info("This Messge Will be printed only if the info log level is enbled"
     + " for the class 'LoggerExampleClass' from Liferay Server Administration");
    }
    

    To Check The Log Other Levels of a Logger.
    _log.isInfoEnabled();
    _log.isWarnEnabled();
    _log.isErrorEnabled();
    _log.isDebugEnabled();
    _log.isFatalEnabled();
    _log.isTraceEnabled();
    

    Liferay 7 Logging Example
    Summing up all the parts into a Java class for an easy reference, this Liferay Portlet Example can give you clear idea of the Logging System in Liferay, Use the below code snippet to know more about the loggers in liferay.


  • Liferay 7 Interview Questions

    Liferay 7 Interview Questions


    Liferay 7 Interview Questions, There are number of Liferay 7 DXP Interview Questions asked In Liferay Portal Interview, There can be different variance in the Questions for Beginners, Experienced Developers and  Architects, Lets see some of them.

    What is Liferay?

    What is Portlet?

    What is Service Builder and What are its uses?

    What are the different module types supported in Liferay 7?

    What is IPC, What are the types of IPC?

    Explain Different IPC's In detail?

    Explain The Permission System in Liferay ?

    What is the difference between Site and an Organization?

    What are the types of Roles available in Liferay?

    What are the differences between Organization and Location?

    What are the New Features Available in Liferay 7?

    What is Kaleo Workflow?

    How to implement Workflow for Custom entity?

    What is the default Role assigned to an user When an user is created?

    What are the types of Pages in Liferay?

    What are the differences between Servlet and Portlet?

    What are the Implicit Objects available in Liferay's Portlet JSP?

    What is OSGI?

    What is a Service and a component in Liferay 7?

    What is the use of OSGI in Liferay 7?

    What are the important Files in Liferay Theme?

    What are the view Template Languages Supported in Liferay Theme?

    Explain The Different types of URL's available in Liferay?

    What is Asset Framework In Liferay?

    How to make a Custom Entity as an Asset In Liferay 7?

    What are the component class Template types available in Liferay 7?

    What is Model Listener How to Implement Model Listener In Liferay 7?

    What is Message Bus, How to Implement Message Bus in Liferay 7?

    How to Configure Multiple Databases in Liferay 7?

    Explain the steps to create Friendly in Liferay 7 Portlet?

    Explain the Steps to Integrate LDAP In Liferay 7?

    Explain Site Template In Liferay 7?

    Explain Administration In Liferay 7?

    Explain Dynamic Query In Liferay with example?

    How to Implement Custom SQL in Liferay 7?

    How To Override A Module's JSP and Portal JSP In Liferay 7?

    Explain all the options available in Liferay 7 Service Builder Module?

    What are the Password Encryption types supported in Liferay 7?

    What is Expando in Liferay, Explain The Tables and Taglibs Used to access the Expandos?

    Explain Spring MVC Portlet Annotations?

    Explain the Configuration Files in Spring MVC Portlet?

    What is Structure and Template Liferay 7?

    How To Make an Entity With Composite Key?

    What are the Differences between JSR-168 and JSR-286?

    What are the types portlet supported by Liferay Other than Liferay MVC Portlet?

    Explain the different Properties in the Manifest File In Liferay 7 Bundle?

    What is product menu in Liferay 7, How To customize the control panel in Liferay 7?

    What is Elastic Search in Liferay 7? What are its uses?

    What is Boolean Query in Liferay 7?

    What are Out of Box Portlet(OOB) available in Liferay 7?

    What are best Practices in Liferay 7?

    What is Document and Media Portlet and What are its uses?

    What is Dynamic Data List(DDL) in Liferay 7?

    How to implement Recycle Bin(Trash) for a Custom Entity in Liferay 7?

    How yo add Portlet to Control Panel category?

    What is a Role in Liferay 7? Explain in detail?

    What is User Group in Liferay 7?

    How to implement Import/Export functionality for custom model Portlet?

    What is Portlet Preferences?

    What is Portal Preferences?

    What is Window State and What are all Window States available in Liferay?

    Explain the Portlet Lifecycle in Liferay?

    Explain the Portlet Phases in Liferay?

    Mention few Table in Liferay related to User?

    What are Login types supported by Liferay other than Email Id?

    What is Staging in Liferay and What is uses?

    How to Configure a Default Landing Page for a Site in Liferay?

    What are the analytics supported in Liferay?

    What are the Document Management Repositories supported by Liferay 7?

    What are steps to integrate Alfresco DMS in Liferay 7?

    What is an Application Display Template and What are its uses?

    What are Portlet Bridges supported by Liferay 7?

    What are Document stores supported by Liferay 7?

    Explain the Technical Architecture of Liferay 7 in detail?

    What are steps to Integrate Solr 5 in Liferay 7?

    How to implement SSO in Liferay 7?

    What is Page Template?

    Explain the Classes & Files Generated By the Service Builder Lieray 7?

    Explain the Database Cache Mechanism in Liferay?

    What is Service Component Number in Liferay?

    Explain Search Container and Its Tags?

    What is the role of a Portlet Container Explain In Details?

    How To implement Configuration Mode for a Liferay MVC Portlet?

    Explain the types of Portal?

    What are the Pre-requisite to Install Liferay 7 In Local Machine?

    How to Embed a Portlet Inside a Portlet In Liferay 7?

    How to Embed a Portlet Inside Theme In Liferay 7?

    How to Embed a Portlet Inside Layout In Liferay 7?

    Explain The Anatomy of Portlet In Liferay 7?

    Explain The Anatomy of Theme In Liferay 7?

    Explain The Anatomy of Layout In Liferay 7?

    What are the types of exceptions thrown while using the Service Builder API?

    What is Colour Scheme In Liferay Theme?

    What is a Site in Liferay?

    What is a Role in Liferay?

    What is a Organization in Liferay?

    What is a User in Liferay?

    What is a UserGroup in Liferay?

    How to Integrate Sonar Cube In Liferay 7 Module?

    How to COnfigure Jenkin For the Liferay Projects?

    How To Configure ReCaptcha In Liferay 7?

    What is a Upgrade Processor In Liferay and How to Implement it?

    What is a Startup Action In Liferay and How to Implement Startup Action?

    How to Implement ShutDown Hook in Liferay 7?

    What is PortletConfig Object In Liferay ?

    How to Implement Localization In Liferay 7?

    How to access files from Language.properties files?

    How to fetch values from Expando tables?

    What are the Important Utility Classes available in Liferay 7?

    How to Implement Error Message and Success Messages In Liferay 7?

    What is an IFrame Portlet?

    What is an Proxy Portlet?

    How to enable web services for an Entity?

    What is GoGo Shell and How to Use It In Liferay 7, What are the gogo shell commands in Liferay 7?

    What the Gradle commands available in Liferay 7 ?

    What the Maven commands available in Liferay 7 ?

    What is portal-ext.properties file?

    What is portal-setup-wizard.properties file?

    How to Index(add) Custom Entity Into Elastic Search or Solr?

    How to Embed a Web Content(Journal Article) In Theme?

    How to Embed a Web Content(Journal Article) In Layout?

    How to Embed a Web Content(Journal Article) In Portlet?

    How to create a new Struts Action for a Existing OOB Portlet In Liferay 7?

    How Provide Model(Entity) level Permission for a Custom Entity in Liferay 7?

    How to Restrict User To Perform Certain Action Inside a Portlet?

    What is Resource Permission And Resource Action Liferay 7?

    How to Configure EH Cache In Liferay 7?

    How to Configure CDN In Liferay 7, What are its uses?

    How to Configure Domain Name (Virtual Host) In Liferay 7, What are its uses?

    What are the Differences between Liferay 7 CE(Community Edition) and Liferay 7 DXP(Enterprise
    Edition)?

    What is IndexPostProcessor In Liferay 7?

    What is ActionCommand, ResourceCommand and RenderCommand In Liferay 7?

    What is Portlet Filter in Liferay 7, How to Implement it?

    What is Class Loader ? What are the types of ClassLoaders available in Liferay 7?

    What are the Portlet Modes Available in Liferay 7 and Explain them?

    What is the Directory (Folder) Structure of a Portlet Module In liferay 7?

    What are the Databases Supported by Liferay 7?

    What is HotFix Patching and How to do HotFix Patching in Liferay 7 DXP?

    What are the steps to migrate plug-in from Liferay 6.2 to Liferay 7 DXP?

    How to Configure Tomcat Clustering in Liferay 7? What are its Uses?

    Explain The Flow on How an HTTP request is Converted to Portlet Request In Liferay ?

    How to Use JUnit In Liferay Portlet Classes?

    Explain the Parameters available in the Portlet URL and their uses?

    What is Multi tenancy In Liferay ?

    Currently there are around 150 Questions,  I am planning to increase the questions count to 500, then I Will Categorize the Questions and based on difficulty level and categories, As Soon Soon as Possible.



  • AUI Popup and AUI Modal Dialog In Liferay 7

    AUI Popup and AUI Modal Dialog In Liferay 7

    AUI Popup and AUI Modal Dialog In Liferay 7

    Liferay has provided AUI Popup and AUI Modal Dialog Using them we can create the aui popup window in Liferay, If you are planning to perform any render or actions inside the popup the AUI Popup Window is ideal, as it is rendered Inside an IFrame action success message and error messages can be shown in the popup , if you're not performing actions rather showing confirm box or Ajax is involved in the interaction you can go ahead with modal Dialog, it is not rendered in IFrame.

    Environment
    Liferay IDE 3.1.2 GA3
    Liferay CE Portal Tomcat 7 GA4
    JDK 8
    MySql 5.7

    There are many ways in which you can create a popup in JSP, and render the content, content can be  JSP or The content of a DIV, Lets see how to render a JSP Inside the Popup First

    AUI Popup Using 'UseDialog'

    Liferay 7 has come up with one of the coolest and simplest way which allows you to render JSP in other words a Render URL without any AUI Script for the popup.


    AUI Popup and AUI Modal Dialog In Liferay 7






    Using AUI Script

    If you want to Render a JSP in your popup and you want to define your own popup size, title, and other attributes then you can use the AUI Script Popup to render Customized Popup in your portlet 


    AUI Popup and AUI Modal Dialog In Liferay 7





    Using Modal Dialog

    If You Just Want to render the content of a DIV into the Popup you can use the Modal Dialog 
    Note : Don't perform any action in the Modal Dialog Popup, it is not suitable for performing any action or render in the popup.



    AUI Popup and AUI Modal Dialog In Liferay 7

    You can download the complete source code from the below url and please deploy and let me know if it have any issues.


    Source Code


  • Implicit Objects In Liferay 7 JSP

    Implicit Objects In Liferay 7 JSP

    Implicit Objects In Liferay 7 JSP

    Implicit Objects In Liferay JSP, We Can access Various Information related to user, portlet, layout, theme, etc in the JSP files Using Liferay JSP Implicit Objects . Lets see what are all Complete List of Liferay Implicit Objects available in Liferay 7.

    Environment
    Liferay IDE 3.1.1 GA2
    Liferay CE Portal Tomcat 7 GA4
    JDK 8
    MySql 5.7


    In Liferay have two taglibraries which grant access to Liferay JSP Implicit Objects.

    Implicit Objects From portlet:defineObjects Taglib

     

    To Get all these implicit objects, <portlet:defineObjects /> must be added In the JSP, these objects holds the information about the portlet parameters and  related data.

    •  actionRequest
    • actionResponse
    • eventRequest
    • eventResponse
    • liferayPortletRequest
    • liferayPortletResponse
    • portletConfig
    • portletName
    • portletPreferences
    • portletPreferencesValues
    • portletSession
    • portletSessionScope
    • renderRequest
    • renderResponse
    • resourceRequest
    • resourceResponse
    • searchContainerReference


    Implicit Objects From liferay-theme:defineObjects Taglib

     

    To Get all these implicit objects, <liferay-theme:defineObjects /> must be added In the JSP, these objects holds various information related user, portlet, layout, theme, portal, permissions etc.

    • account
    • colorScheme
    • company
    • contact
    • layout
    • layouts
    • layoutTypePortlet
    • locale
    • permissionChecker
    • plid
    • portletDisplay
    • portletGroupId
    • realUser
    • scopeGroupId
    • theme
    • themeDisplay
    • timeZone
    • user

     

    Implicit Objects From JSP

    These are the default implicit objects available from the JSP, you dont have to include any taglib for them 
    • application
    • config
    • out
    • page
    • pageContext
    • request
    • response
    • session


    All Implicit Objects



    Use The above JSP a Reference for Taglibs and Imports


  • Portlet Window States In Liferay

    Portlet Window States In Liferay

    Portlet Window States In Liferay

    A Portlet Window State Indicates area of the portlet to be rendered by the portlet, Basically 3 Portlet States are supported by the JSR Portlet Specification Standard, Liferay Provides 2 Additional States For more flexibility on the Render State Controll.

    1. Normal
    2. Maximized
    3. Minimised
    4. Popup
    5 .Extended


    <%@page import="com.liferay.portal.kernel.portlet.LiferayWindowState"%> <%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%> <%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui"%> <%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet"%> <%@ taglib uri="http://liferay.com/tld/theme" prefix="theme"%> <%@ taglib uri="http://alloy.liferay.com/tld/aui" prefix="aui"%> <portlet:defineObjects /> <theme:defineObjects /> This is the <b>Window State</b> portlet in View mode. <!-- JSR Specific Portlet Window States --> <portlet:renderURL var="normarURL" windowState="<%=LiferayWindowState.NORMAL.toString()%>"/> <portlet:renderURL var="maximizedURL" windowState="<%=LiferayWindowState.MAXIMIZED.toString()%>"/> <portlet:renderURL var="minimisedURL" windowState="<%=LiferayWindowState.MINIMIZED.toString()%>"/> <!-- Liferay Specific Portlet Window States --> <portlet:renderURL var="popupURL" windowState="<%=LiferayWindowState.POP_UP.toString()%>"/> <portlet:renderURL var="exclusiveURL" windowState="<%=LiferayWindowState.EXCLUSIVE.toString()%>"/> <br> <aui:button href="${normarURL}" value="Normal"/> <br> <aui:button href="${maximizedURL}" value="Maximized"/> <br> <aui:button href="${minimisedURL}" value="Minimised"/> <br> <aui:button href="${popupURL}" value="Popup"/> <br> <aui:button href="${exclusiveURL}" value="Exclusive"/>


    Deploy The portlet to know how Window States Works in Liferay Portlet