Saturday, July 27, 2013

How to create user library in Eclipse

User library allowed us to create reusable/shared libraries in Eclipse that can be used in multiple projects within the same workspace.

Steps:

Creating a User Library

1. Go to User Libraries
Window > Preferences > Java > Build Path > User Libraries

Wednesday, July 24, 2013

Reading and writing date value in excel with Apache POI

This post shows the code snippet on how to read and write java.util.Date object to an excel.
Writing date into excel is easy; 
Reading date value from excel we must make sure the cell type is date to avoid exception.

Reading date value from excel file

Cell cell = row.getCell(i);
Date dateValue = null;
if(cell.getCellType() == cell.CELL_TYPE_NUMERIC) {
    if (DateUtil.isCellDateFormatted(cell)) {
        dateValue = cell.getDateCellValue();
    }
}

Sunday, July 21, 2013

How to access Liferay Local Service API

Other than accessing Liferay Service through web service, Liferay provides local API as well for Liferay Portlet developers to access Liferay information locally.

To know more about what local services  Liferay exposed, please refer the javadoc.

This post will show a simple example on how to access Liferay local service.

Requirement:
1. Liferay Development environment has been setup.
2. Portlet created in Liferay

Accessing Liferay Web Service with Liferay Portal Client

During development, Liferay developers might want to access to Liferay information, eg, user details.
But it is not suppose to access to Liferay database directly.
thus, Liferay exposed a list Web Services for us to access through Liferay Portal Client

Liferay's services could be accessed through local API, for more details, please refer here.

Requirement:
1. Liferay Portal 6.1.1 ga2
2. Liferay Portal Client 6.1.1 ga2
3. Eclipse Juno
4. Liferay Development environment has been setup

Wednesday, July 17, 2013

How to create multiple lines message p:tooltip

From the PrimeFaces online demo, showing the usage of <p:tooltip /> component.
But all the samples displaying only single line message.
p:tooltip demo

Sometimes, the system requirements might need to display the message in multiple lines instead of just a long single line message.

this could be achieved by putting in a <h:panelGroup /> into the <p:tooltip /> component.
Then all content could be put inside the panelGroup, eg, <p:panel />, <p:graphicImage />, etc.

Tuesday, July 16, 2013

How to assign members to a password policy

Related Liferay Password Policy topics:
  - Setting password syntax in Liferay
  - Enable Liferay password expiration
  - Enable Liferay password lockout
  - Assign members to a password policy

In Liferay, we can create multiple Password Policies for different sites, organizations, or members due to different requirements of different sites, organizations. 
certain organizations might request to have complex password format; certain organizations might simply need a login password.
So this could be handled by creating different Password Policy for different organization.

In this post, the organization MyOrg will be assigned to the newly created password policy.
All Members (MyOrgUser01, MyOrgUser02) which are under the MyOrg organization will be associate with the same password policy.

Saturday, July 13, 2013

How to enable Liferay password lockout

Related Liferay Password Policy topics:
  - Setting password syntax in Liferay
  - Enable Liferay password expiration
  - Enable Liferay password lockout
  - Assign members to a password policy

Password Lockout in Liferay refers to the locking of user account when user failed to enter the correct login id and password for the system defined number of login failures.
By default, there is no lockout for user account and user is allowed for any number of failure attempts.

In Liferay, Administrator has the options to enable the Password Lockout, and also options to unlock user account by the Administrator only or system defined duration.


Thursday, July 11, 2013

How to enable Liferay password expiration

Related Liferay Password Policy topics:
  - Setting password syntax in Liferay
  - Enable Liferay password expiration
  - Enable Liferay password lockout
  - Assign members to a password policy

Password expiration is a security consideration to force a user to change his/her password for a pre-defined duration.
eg, if the password expiration is 1 year, a user registered on 1st Jan 2013 must change his/her password on 1st Jan 2014.

The password expiration policy is built-in in Liferay but disabled by default.
From security perspective, a production Liferay portal should enable the built-in password expiration.
and below are the steps.

Sunday, July 7, 2013

Setting password syntax in Liferay

Related Liferay Password Policy topics:
  - Setting password syntax in Liferay
  - Enable Liferay password expiration
  - Enable Liferay password lockout
  - Assign members to a password policy

By default, Liferay accepts any format of password.
But it could be changed by the Administrator at any point of time.

Liferay provides an easy to configure Password Policies for Administrator to change to any desired password syntax/format.

Steps:
1. Login as Administrator

2. Navigate to Password Policies
    Go to > Control Panel > Portal > Password Policies

How to edit Liferay email notification templates

There are several pre-defined email notification templates in Liferay.
Eg. User Account created notification, Password Changed notification, etc.

As an open source CMS, Liferay allowed us to customize the notification templates with our preferences easily from the screen.

Steps:
1. Login as Administrator.

2. Navigate to Portal Settings
    Go to > Control Panel > Portal > Portal Settings

Saturday, July 6, 2013

Retrieving image from database made easy by p:graphicImage


In a Java web application, if we are going to display image(s) from database (stored in blob).
Normally it is going through an Image Servlet to convert the byte[] to an image file before render it in the screen.

With PrimeFaces's <p:graphicImage />, no additional Image Servlet is required.
What we need here is just to convert the byte[] to StreamedContent.

Converting byte[] to StreamedContent

public StreamedContent getImage() {
    byte[] imageInByteArray = IMAGE_IN_BYTE_ARRAY_FROM_DB;
    return new DefaultStreamedContent(new ByteArrayInputStream(imageInByteArray), "image/png");
}

Displaying StreamedContent in p:graphicImage

<p:graphicImage value="#{imageBean.image}" />


Done!!

LinkWithin

Related Posts Plugin for WordPress, Blogger...