Wednesday 9 September 2015

Hook and Ext Interview Question

can you list some common scenarios where hooks can be used?

Some common scenarios which require the use of a hook are


1. the need to perform custom actions on portal startup or user login,
2. overwrite or extend portal JSPs,
3. modify portal properties,
4. replace a portal service with your own implementation.














In general, there are four kinds of hook parameters:
  1. portal-properties (called portal properties hooks)
  2. language-properties (called language properties hooks)
  3. custom-jsp-dir (called custom JSPs hooks) and
  4. service (called portal service hooks)
portal properties hooks allow runtime re-configuration of the portal. 

Language properties hooks allow us to install new translations or override few words in existing translations.

JSP hooks provide a way to easily modify JSP files without having to alter the core of the portal



Portal service hooks provide a way to easily override portal services. 

where hooks can be used?

1. Overriding out of the box portlet JSPs (Custom JSPs)

2. Overriding Portal Services

3. Providing some custom actions for various events (pre login, post login...etc)

4. customizing the language.properties

can you use hook to override language-en.properties?

Yes. we can use hooks to Override a Language.properties File allowing you to change any of the messages displayed by Liferay to suit your needs

can you give some examples of portal service overiding using hooks?

Overriding a Portal Service

  •  Overriding UserLocalService
  • OrganizationLocalService: add, delete and retrieve organizations. Also assign users to organizations and retrieve the list of organizations of a given user.
  • GroupLocalService: add, delete and retrieve communities.
  • LayoutLocalService: add, delete, retrieve and manage pages of communities, organizations and users.
  • when can we use hoooks?

    Hook plugins can be used to modify portal properties or to perform custom actions on startup,
    shutdown, login, logout, session creation and session destruction.


    Using service wrappers, it is possible for a hook plugin to replace any of the core Liferay services
    with a custom implementation.


    Hook plugins can also replace the JSP templates used by any of the default portlets, allowing you to customize their appearance as desired

When can we use Ext Plugins?

1. Using Ext Plugins we can customize Struts actions of Liferay Portal. 

Ex: We want to send email to user via JMS when user is banned. we can extend MessageBoard portlet's BanUserAction.

 Hooks supports Struts Action extension in Liferay 6.1


2.we can extend some of the Liferay's Listeners which are not supported in Hooks

3.we can use extension plugin to include some custom filters

 Ex: In every web application we may want to implement some new filters. Using ext plugin you can implement our own filter and tell liferay to include it. we can add our filters in Web-ext.xml

4. Extending Liferay's portal.properties

 Ex: if we want to override Liferay's PermissionChecker class then we can do it. create new Permission Checker class and mention in portal-ext.properties

# # Set the default permission checker class used by
# com.liferay.portal.security.permission.PermissionCheckerFactory to check
# permissions for actions on objects. This class can be overriden with a
 # custom class that implements # com.liferay.portal.security.permission.PermissionChecker.
 # #permissions.checker=com.liferay.portal.security.permission.SimplePermissionChecker permissions.checker=com.liferay.portal.security.permission.AdvancedPermissionChecker


 5. we can extend some feature of liferay-portlet.xml through liferay-portlet-ext.xml

Differences between hooks plugin and ext plugin?

Liferay can be customized using either hook plugins or Ext plugins. best way  is to try

doing all your customizations as hooks if possible.

If you find something you can’t do in a hook—maybe you need to customize a
property that isn’t yet supported by hooks, extend an internal Liferay class, implement
a custom PermissionChecker, or extend a Liferay Struts action—you can use the Ext
plugin to do this.

1. Hooks are recommended way of extension.  Maintenance is easy
   Ext plgin suggested when there is no way of implementing required functionality using Hooks

2. Hooks are hot deployable . Ext Plugins are not hot deployable

3. Hooks doesn't require server restart. Ext plugins requires server restart before taking into effect

4. Hooks stays as separate components. those are not overriding  liferay's code. System load at runtime to override the behavior.

Ext plugins changes replaces the liferay's code directly.


5. Hooks undoing is easy.. Ext plugin undoing is not easy. Need almost fresh installation

6.in Extension , we can customize almost everything. we will have access to all Liferay's APIs

7. Ext plugin implementation is not easy as Hook plugin

8. While Liferay upgradation we may see some surprises in your ext plugin. some API might be used in liferay implemenation which is used in your Ext plugin. so you have to rewrite your ext plugin


9. And because code from Ext plugins overlays the code in Liferay, you can’t
have more than one Ext plugin that contains a struts-config-ext.xml file, and you have
to put all your portlets into one big, monolithic Ext project


10. Do You need to change the logic of a Struts action in one of the built-in portlets. ? Then we may need Ext Plugin

If I wan to do some activity after sign on.how can you do that?

Suppose I have requirement that Immediately  after user sign in we need get some data from
an ERP system. how can we do that?

We can use Liferay's Hooks.  Hooks can be used to perform custom actions on certain common portal events such as user log in or system start up.

we can define actions for events in portal.properties.
 #
 # Login event
 #

 login.events.pre=com.suresh.MyLoginAction
login.events.post

  #
  # Logout event
  #

 logout.events.pre=

logout.events.post=   

No comments:

Post a Comment