Thursday, December 18, 2014

Liferay JSP Tag Libraries Introduction

Liferay have given many tag libraries to make development easy and rapid. Liferay have developed their own tag libraries which we can use extensively in liferay development.

What is Tag Library?

Tag library is set of JSP tags and each tag have its own syntax and required attributes.

What is JSP Tag?

JSP tag is way to avoid the writing repeated code snippets in the JSP pages. Each tag have its own piece of presentation markup(html/java script/css/java code) code which can be encapsulates as a separate part and it will be identify by the specific notation called Tag.

When we use the tag in the JSP page it will be replaced by respective code snippet/presentation markup at the time of page rendering.

When we work with JSP pages we aware of JavaServer Pages Standard Tag Library (JSTL)

Whats is JSTL?

The Java Server Pages Standard Tag Library (JSTL) is a collection of useful JSP tags which encapsulates core functionality common to many JSP applications.

We have many tag libraries in JSTL and the following are JSTL tag Libraries
  • Core Tags
  • Formatting tags
  • SQL tags
  • XML tags
  • JSTL Functions
JSP Tag Libraries Artifacts

When we work with tag libraries we have three artifacts we need to consider
  1. Tag Library Description(TLD)
  2. Tag Library URI
  3. Tag Library Implementation JAR file
Tag Library Description(TLD)

Each tag library have its own Tag Library Description(TLD) file and its a xml file consist of tag information like tag name, tag attributes, what attributes are required and what are optional.

Tag Library URI

Tag Library URI is unique URL to identify the tag library,this will be used in JSP page to import tag libraries and we will use Tag Library URI in application deployment descriptor(web.xml) to integrate tag library with application. Tag Library URI is represented in TLD file.

Example:

<uri>http://alloy.liferay.com/tld/aui</uri>

Tag Library Implementation JAR file

Tag Library Implementation JAR file is a jsp tags implementation java classes make it as JAR file and we need to add this jar file in application class path that is application lib directory or other server lib directory.

Usage of JSP Tag Libraries

We already know JSP tag libraries are used only in JSP pages. If we want use JSP tag Libraries in Web application JSP pages then we have to follow set of following steps.
  1. Register Tag Library in Application Deployment Descriptor(web.xml)
  2. Add Tag Library TLD file in WEB-INF directory
  3. Add Tag Library Implementation JAR file in Application Class Path
  4. Refer Tag Library URI in JSP page
Register Tag Library in Application Deployment Descriptor(web.xml)

First we need to register tag libraries in application web.xml file so that application can use tag in the JSP pages. When we register Tag libraries in web.xml we need to know tag library URI and Location of TLD file.

The following is registering tab libraries in web.xml file

<jsp-config>
<taglib>
<taglib-uri>http://liferay.com/tld/aui</taglib-uri>
<taglib-location>/WEB-INF/tld/aui.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/portlet_2_0</taglib-uri>
<taglib-location>/WEB-INF/tld/liferay-portlet.tld</taglib-location>
</taglib>
</jsp-config>

Note:

Configuration should be enclosed by <jsp-config/> tag. In the above configuration we have registered two tag libraries.

Add Tag Library TLD file in WEB-INF directory

We need to add Tag Library TLD file in the application WEB-INF directory. We can directly place in WEB-INF or we can create separate directory and we can place there. Make sure the path of TLD file that we have given in web.xml file to register tag library.

Example:

<taglib-location>/WEB-INF/tld/liferay-portlet.tld</taglib-location>

Add Tag Library Implementation JAR file in Application Class Path

Every tag library have its implementation java JAR file and this should be available in application class path that is WEB-INF/lib directory.

Example Implementation JAR files:

For JSTL (jstl-api.jar,jstl-impl.jar)
For Liferay(util-taglib.jar)

Refer Tag Library URI in JSP page

Its final step where we need to refer tag library in JSP page so that we can use respective tags in the JSP pages.

The following is the way to refer Tag Library in JSP page

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>

We need to give the tag library URI path that is available in TLD file and we will use prefix name to identify the tag library in the JSP page.

Example Usage of Tab Library Tags in JSP Page

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>

<portlet:actionURL var="sendUserNotification" windowState="normal" name="sendUserNotification">
</portlet:actionURL>

Note:

We will use prefix name to each tag notation and each tag may have attributes and we need to pass it in the tag.

Liferay JSP Tag Libraries

Apart from JSTL tag libraries Liferay also implemented their own tag libraries which we will use in liferay plugins development.

Liferay have many tag libraries for different contextual use and each tag libraries have collection of tags we can use in JSP pages to make it good presentation and rapid UI development.

The following are the Liferay Tag Libraries
  1. Portlet Tag Library
  2. Liferay Portlet
  3. Liferay Security
  4. Liferay AUI
  5. Liferay UI
  6. Liferay Util
Note:

Each tag library have many tags and its based on usage its made it as different libraries.

Usage Of Liferay Tag Libraries in Portlet Development

When we work with Plugin portlet development we extensively use the liferay tag libraries and its tags in the JSP pages.

Here interesting thing is Liferay Tag Libraries registering with portlet will be take care by the liferay auto deployment process so we need not to do manually registering the tag libraries.

Only we need to refer tag library URI information in the JSP page so that we can use tags in the JSP page.

The following is referring all Liferay Tag Libraries in the JSP page

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>
<%@ taglib uri="http://liferay.com/tld/security" prefix="liferay-security" %>
<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
<%@ taglib uri="http://liferay.com/tld/util" prefix="liferay-util" %>

Example Usage of Liferay Tag from Portlet Tag Library in the JSP page

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>



<portlet:actionURL var="sendUserNotification" windowState="normal" name="sendUserNotification">

</portlet:actionURL>

The following is reference links to know each and every liferay JSP tag information

Note:

Each Library have many tags and that will be used in our portlet development.

How does Liferay Auto Deployment Process Registering the Liferay Tag Libraris in the Portlet plugin

When we create portlet from Liferay IDE there is no information in portlet web.xml file related to liferay tag libraries and no JAR file in portetl Lib directory and No TLD file in Portlet WEB-INF directory.

Once we deploy the portlet then portlet will be deployed in the application server deployment directory

If we use Tomcat then we can see portlet deployed in webapps directory(tomcat-7.0.42/webapps)

Observations:

Find your Poertlet in webapps directory and open web.xml file then you can see following configuration. Which shows that its registered all Liferay Tag Libraries

Example Path:

/tomcat-7.0.42/webapps/DockBarCustomNotification-portlet/WEB-INF/web.xml

<jsp-config>
<taglib>
<taglib-uri>http://liferay.com/tld/aui</taglib-uri>
<taglib-location>/WEB-INF/tld/aui.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/portlet_2_0</taglib-uri>
<taglib-location>/WEB-INF/tld/liferay-portlet.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://liferay.com/tld/portlet</taglib-uri>
<taglib-location>/WEB-INF/tld/liferay-portlet-ext.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://liferay.com/tld/security</taglib-uri>
<taglib-location>/WEB-INF/tld/liferay-security.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://liferay.com/tld/theme</taglib-uri>
<taglib-location>/WEB-INF/tld/liferay-theme.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://liferay.com/tld/ui</taglib-uri>
<taglib-location>/WEB-INF/tld/liferay-ui.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://liferay.com/tld/util</taglib-uri>
<taglib-location>/WEB-INF/tld/liferay-util.tld</taglib-location>
</taglib>
</jsp-config>

Now Open Portlet WEB-INF directory then you can see tld directory once you look into tld directory then you can see all liferay tag libraries tld files.

Example Path:

/tomcat-7.0.42/webapps/DockBarCustomNotification-portlet/WEB-INF/tld

Liferay Tag Library TLD files

aui.tld
liferay-portlet.tld
liferay-portlet-ext.tld
liferay-security.tld
liferay-theme.tld
liferay-ui.tld
liferay-util.tld

As we know each tag library have its own implementation jar file. Liferay also implemented java classes for all libraries and made it as one jar file called util-taglib.jar and it will be available in portlet lib directory(/tomcat-7.0.42/webapps/DockBarCustomNotification-portlet/WEB-INF/lib)

From above all observations we can understand that in the liferay portlet development we no need to do any manual configuration to register the liferay tag libraries and Liferay auto deployment process will take all necessary configuration to make use of liferay tag libraries in portlet development that is in jsp pages.

Note:

Liferay Auto deployment process only resisted the Liferay tag libraries in the portlet not JSTL tag libraries.

Using JSTL Tag Libraries in Liferay Portlet Plugin

As we know liferay auto deployment is only configure the liferay tag libraries but we also have many useful tag libraries that is JSTL tag libraries. When we want use JSTL tag libraries such as Core Tags ,Formatting tags ,SQL tags ,XML tags ,JSTL Functions then we are the responsible to register the JSTL tag libraries in the portlet development.

Assume we want to use JSTL core tag library

Use JSTL tag Libraries in the Portlet Development Using Liferay IDE

Liferay IDE provide very easy way to configure the JSTL tag libraries in Plugin Portlet development.

Go to your Plugin portlet in the eclipse project explorer

Double Click on “liferay-plugin-package.properties file its in portlet WEB-INF directory.

One we open this file it will be open in “properties” view mode as follows


You can see two inputs fields “Portal Dependency Jars” and “Portal Dependency Tlds” and we can also have Add buttons.

As we know when we work with tag libraries we need tag library implementation JAR file and Tag library TLD file.

jstl-api.jar, jstl-impl.jar” are the JAR files that was implemented the JSTL tag library and its have different TLD files like c.tld for JSTL core tags.

Now “Portal Dependency Jar” section click on Add button then it will open dialog there you can find available JAR files list and search for “jstl-api.jar,jstl-impl.jar” files and select both files and then click on OK .

The following screen shows you adding JSTL jar files


Now “Portal Dependency Tlds” section click on Add button then it will open dialog there you can have available JAR files list and search for “c.tld” file and select it then click on OK .

The following screen shows you adding JSTL TLD files


We have added JAR files and TLD file finally you can save the file(Ctrl+S).

The following screen shows added dependency jar files and dependency TLD files in the “liferay-plugin-package.properties

The following is source view of “liferay-plugin-package.properties

Liferay Plugin Portlet development when we need portal dependency jar files or other files like tld we will use “liferay-plugin-package.propertiesfile and the following is configuration.

portal-dependency-jars=\
jstl-api.jar,\
jstl-impl.jar
portal-dependency-tlds=c.tld

When we configure portal dependency jar files or tld files in “liferay-plugin-package.propertiesfile then liferay auto deployment process will copy specified JAR files and TLD files from Liferay Portal and Place into the Plugin Portlet appropriate locations like jar files will be placed in the portlet “WEB-INF/lib” directory and TLD files will be placed in the portlet “WEB-INF/tld” directory.

We have configured the JSTL tag libraries in our portlet, now we can use JSTL core tags in JSP pages .

The following is example code in JSP page to use JSTL Core tags

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:if test="<%= MicroblogsPermission.contains(permissionChecker, scopeGroupId, ActionKeys.ADD_ENTRY) && !userPublicPage %>">
<a>Add<p>
</c:if>

How Liferay Auto Deployment Process Configure JSTL Tag Libraries.

Once we add dependency jar files and dependency tld files in “liferay-plugin-package.propertiesfile then following things takes places after successful deployment of portler and these we can observed in deployed portlet in server deployment directory .
Go to tomcat webapps directory and find you pottlet then you can see following things

Observations:

Find your Poertlet in webapps directory and open web.xml file then you can see following configuration. Which shows that its registered all Liferay Tag Libraries

Example Path:

/tomcat-7.0.42/webapps/PortletConfigaration-portlet/WEB-INF/web.xml

<jsp-config>

<taglib>

<taglib-uri>http://java.sun.com/jsp/jstl/core</taglib-uri>

<taglib-location>/WEB-INF/tld/c.tld</taglib-location>

</taglib>

</jsp-config>

Now Open Portlet WEB-INF directory then you can see tld directory once you look into tld directory then you can see c.tld file

Example Path:

/tomcat-7.0.42/webapps/PortletConfigaration-portlet/WEB-INF/tld

As we know each tag library have its implementation jar file. JSTL implementation jar files called “jstl-api.jar, jstl-impl.jar” and it will be available in portlet lib directory(/tomcat-7.0.42/webapps/PortletConfigaration-portlet/WEB-INF/lib)

From above all observations we can understand that liferay portlet development when want add JSTL tag libraries we just need to specify the dependency jar files and dependency tld files in the “liferay-plugin-package.propertiesfile then Liferay auto deployment process will take all necessary configuration to make use of JSTL tag libraries in portlet development that is in jsp pages.

Manual Configuration to Use JSTL Tag Library in Plugin Portlet.

  1. Configure JSTL tag information in web.xml
  2. Add JSTL Implementation JAR file in Portlet lib Directory
  3. Add JST td file in portlet WEB-INF directory
  4. Refer Tag Library in JSP page 
 
Author

Wednesday, December 17, 2014

Liferay Portal Properties Hook Plugin

Liferay Hooks are used to customize the liferay portal. We have many kinds of hook plugins one of the hook is Portal Properties hook.

Introduction to Liferay Hook Plugins 

Portal properties hook overriding the existing portal properties and Portal properties hook can modify the some of the portal properties not all the portal properties. The modifiable list of properties are specified in liferay-hook_6_x_x.dtd file. 

If the properties are not listen in the liferay-hook_6_x_x.dtd file then we cannot modify it from portal properties hooks. Assume we want to modify login.events.pre ,login.events.post properties then we will use Portal Properties Hooks. 

If the portal properties are not listed in above then its not possible to override from portal properties hook plugins then we have to use portal-ext.properties file.

Existed Behavior of Liferay portal Create Account Page

In the liferay portal create account page we cannot find password field that user can create his own password at the time of registration.

After registration  user will get mail with auto generated password to login into portal and then he/she can change the password from his/her my account page password section.

Existed User Create Account Page in Liferay



Customer Expected Behavior of Create Account Page

Now assume we want create account page so that user can choose his/her own password at time of registration

The following are basic steps we should consider

Here our requirement is customize the existed liferay portal so best choice is hook plugins.

We have many kind of hook plugins so first we need to check with any portal property that can full fill out requirement.

Need to search in  liferay-hook_6_x_x.dtd   for appropriate portal property that can solve our problem.

If we find relevant portal property then we will choose portal  properties hook Plugin to implement it otherwise we should go for other type of hook Plugin.

In our case “login.create.account.allow.custom.password” is full fill our requirement. “login.create.account.allow.custom.password” is portal property that will allow user to choose custom password at the time of registration means it will accommodate two more user input fields in the create account page.

Implement Solution using Portal Properties Hook

Direct Steps

Step:1

Create Liferay Hook Project using below Article

Liferay Hook Plugin Development with Liferay IDE

Step:2

Configure portal properties file name in “liferay-hook.xml”  its in hook Plugin WEB-INF directory (/Sample-hook/docroot/WEB-INF/liferay-hook.xml) 

Add following configuration in “liferay-hook.xml

<hook> 
<portal-properties>portal.properties</portal-properties> 
</hook>

Step:3

Create “portal.properites” file in Plugin Hook src directory (/Sample-hook/docroot/WEB-INF/src/portal.properties)

Step:4

Add overridden property name and its value in “portal.properites” file that is  Plugin Hook src directory and possible overridden portal properties are available in “liferay-hook_6_x_x.dtd”

Add Overridden Portal Property in hook “portal.properties” files as follows

login.create.account.allow.custom.password=true

Step:5

Once we done all above steps deploy the Hook Plugin by double click on deploy target in the ANT view of eclipse or you can use “ant deploy” target from command prompt.

Once Portal Properties Hook Plugin successfully deployed ,now go to create account page then you can see password fileds in the page

The following screen shows you password filed




Crete Portal properties Hook using Liferay IDE Graphical User Interface

First we need to create Liferay Hook Plugin please follow the article and Create liferay hook Plugin

Liferay Hook Plugin Development with Liferay IDE

Now select the created hook Plugin in the project explorer

Go to File--> New Liferay Hook Configuration

now you can see dialog window  select portal properties check box then click on next


Now you can see another dialog there you can see two sections in the bottom section is for adding portal properties. Now click on Add button 



Now you will get another window there you can see property name and value input fields . For property name you can see “select” button


Now click on “select” button it will show another dialog to select possible portal properties.

Choose required property then click on OK


Now selected property will be appear in the property filed and enter appropriate values for the property in the values filed.


Click the OK and finally click on the Finish button. Now the portal properties file will be created in the hook src directory (“/Sample-hook/docroot/WEB-INF/src/portal.properties”).

The overridden properties and values are present in the “portal.properties” file



Overriding More Portal Properties

In the project explored go to /Sample-hook/docroot/WEB-INF  and double click on “liferay-hook.xml” file then it will be open in editor and we have two views “source” view and “overview”, default view is “overview”

The following is “overview” of “liferay-hook.xml” 



Note:

All hook related configuration are placed in “liferay-hook.xml” 

In the “overview” you can find “Portal properties”  icon with text ,click on that and check the “Customize Liferay Portal Properties” As soon as you check the box then you can see “portal properties” input field and “portal properties overrides” that can have two sections “Name” and “Value”

The following screen show you required input fields


Now we can see Add icon(+)  click on Add icon then you can see Name and Value fields in the bottom of “Portal Properties Overrides” input field.


Now in the name field you can see browse button. You can click on browse button then you can see dialog window there you can see all possible portal properties that can be overridden and you can have search field to search properties.


Now select required property and click on OK  then it will be appear  in the “Override Name” field and enter appropriate value in “Override Value” field


If we want we can also add more values or you can remove values using Add and Remove icons.

Once we done then save the file (Ctrl+S).

In the source view you can see the “liferay-hook.xml” as follows 


Ass soon as we save the file then portal property name and overridden value will be written in “portal.proerties” file that is in hook Plugin src directory



Once we done all above steps deploy the Hook Plugin by double click on deploy target in the ANT view of eclipse or you can use “ant deploy” target from command prompt.

Once Portal Properties Hook Plugin successfully deployed  then you can see respective changes in the liferay portal.

The following are possible portal properties that we can override using hook plugins

admin.default.group.names 
admin.default.role.names 
admin.default.user.group.names 
asset.publisher.asset.entry.query.processors 
asset.publisher.display.styles 
asset.publisher.query.form.configuration 
auth.forward.by.last.path 
auth.public.paths 
auto.deploy.listeners 
application.startup.events 
auth.failure 
auth.max.failures 
auth.token.ignore.actions 
auth.token.ignore.portlets 
auth.token.impl 
auth.pipeline.post 
auth.pipeline.pre 
auto.login.hooks 
captcha.check.portal.create_account 
captcha.engine.impl 
com.liferay.portal.servlet.filters.*Filter 
company.default.locale 
company.default.time.zone 
company.settings.form.authentication 
company.settings.form.configuration 
company.settings.form.identification 
company.settings.form.miscellaneous 
control.panel.entry.class.default 
convert.processes 
default.landing.page.path 
default.regular.color.scheme.id 
default.regular.theme.id 
default.wap.color.scheme.id 
default.wap.theme.id 
dl.file.entry.drafts.enabled 
dl.file.entry.processors 
dl.repository.impl 
dl.store.antivirus.impl 
dl.store.impl 
dockbar.add.portlets 
field.enable.com.liferay.portal.model.Contact.birthday 
field.enable.com.liferay.portal.model.Contact.male 
field.enable.com.liferay.portal.model.Organization.status 
hot.deploy.listeners 
javascript.fast.load 
journal.article.form.add 
journal.article.form.translate 
journal.article.form.update 
layout.form.add 
layout.form.update 
layout.set.form.update 
layout.static.portlets.all 
layout.template.cache.enabled 
layout.types 
layout.user.private.layouts.auto.create 
layout.user.private.layouts.enabled 
layout.user.private.layouts.power.user.required 
layout.user.public.layouts.auto.create 
layout.user.public.layouts.enabled 
layout.user.public.layouts.power.user.required 
ldap.attrs.transformer.impl 
locales 
locales.beta 
locales.enabled 
lock.listeners 
login.create.account.allow.custom.password 
login.events.post 
login.events.pre 
login.form.navigation.post 
login.form.navigation.pre 
logout.events.post 
logout.events.pre 
mail.hook.impl 
my.sites.show.private.sites.with.no.layouts 
my.sites.show.public.sites.with.no.layouts 
my.sites.show.user.private.sites.with.no.layouts 
my.sites.show.user.public.sites.with.no.layouts 
organizations.form.add.identification 
organizations.form.add.main 
organizations.form.add.miscellaneous 
passwords.passwordpolicytoolkit.generator 
passwords.passwordpolicytoolkit.static 
passwords.toolkit 
phone.number.format.impl 
phone.number.format.international.regexp 
phone.number.format.usa.regexp 
portlet.add.default.resource.check.enabled 
portlet.add.default.resource.check.whitelist 
portlet.add.default.resource.check.whitelist.actions 
rss.feeds.enabled 
sanitizer.impl 
servlet.session.create.events 
servlet.session.destroy.events 
servlet.service.events.post 
servlet.service.events.pre 
session.max.allowed 
session.phishing.protected.attributes 
session.store.password 
sites.form.add.advanced 
sites.form.add.main 
sites.form.add.seo 
sites.form.update.advanced 
sites.form.update.main 
sites.form.update.seo 
social.activity.sets.bundling.enabled 
social.activity.sets.enabled 
social.activity.sets.selector 
social.bookmark.* 
terms.of.use.required 
theme.css.fast.load 
theme.images.fast.load 
theme.jsp.override.enabled 
theme.loader.new.theme.id.on.import 
theme.portlet.decorate.default 
theme.portlet.sharing.default 
theme.shortcut.icon 
time.zones 
upgrade.processes 
user.notification.event.confirmation.enabled 
users.email.address.generator 
users.email.address.required 
users.email.address.validator 
users.form.add.identification 
users.form.add.main 
users.form.add.miscellaneous 
users.form.my.account.identification 
users.form.my.account.main 
users.form.my.account.miscellaneous 
users.form.update.identification 
users.form.update.main 
users.form.update.miscellaneous 
users.full.name.generator 
users.full.name.validator 
users.image.max.height 
users.image.max.width 
users.screen.name.always.autogenerate 
users.screen.name.generator 
users.screen.name.validator 
value.object.listener.*
Author

Recent Posts

Recent Posts Widget

Popular Posts