Sunday, June 26, 2011

Extending Web Form Portlet – Adding File Upload Control

In Liferay Portal, Web Form Portlet is used to create custom forms but the types of field that can be created are limited. One such missing field type is File Upload Control. It’s a common requirement to have file upload control in forms.


Following are the steps to add File Upload Control to Web Form Portlet -


1.  Add a new field type to edit_field.jsp

<aui:option selected='<%= fieldType.equals("file") %>' value="file"><liferay-ui:message key="file" /></aui:option>

2.  Accordingly update the view.jsp to render the your new field

<c:when test='<%= fieldType.equals("file") %>'>

<aui:input cssClass='<%= fieldOptional ? "optional" : StringPool.BLANK %>' label=" <%=HtmlUtil.escape(fieldLabelDisplay) %>" name="<%= fieldName %>" type="file" value="<%=HtmlUtil.escape(fieldValue) %>"/>

</c:when>

3.  Set the preferences for this field in ConfigurationActionImpl.java

boolean isFileUpload = false;

if ("file".equals(fieldType)) {

isFileUpload = true;

}

preferences.setValue("isFileUpload", String.valueOf(isFileUpload));

4.  Finally get the file in WebFormPortlet.java and proceed with your implementation…

File file = uploadRequest.getFile(paramName.toString());

Proceed we the implementation with file object for example save to document library, send in mail etc.

 

 

Thursday, June 23, 2011

liferay Ext Plugin

In Liferay Portal, when working with Ext Plugin the server need to be rebooted after deployment.

But sometimes even after rebooting the server changes are not reflected, because some  jar files and xml files related to ext plugin project don't get updated.

To make sure all the files get updated, stop the server and remove the old files listed below-

./webapps/project-name
./lib/ext/ext-project-name-service.jar
./webapps/ROOT/WEB-INF/lib/ext-project-name-util-bridges.jar
./webapps/ROOT/WEB-INF/lib/ext-project-name-util-taglib.jar
./webapps/ROOT/WEB-INF/lib/ext-project-name-util-java.jar
./webapps/ROOT/WEB-INF/lib/ext-project-name-impl.jar
./webapps/ROOT/WEB-INF/ext-project-name.xml
./temp/liferay/com/liferay/portal/deploy/dependencies/ext-project-name-util-bridges.jar
./temp/liferay/com/liferay/portal/deploy/dependencies/ext-project-name-util-taglib.jar
./temp/liferay/com/liferay/portal/deploy/dependencies/ext-project-name-util-java.jar

After this deploy the ext project and reboot the server.

Enjoy working with Liferay Portal Ext Plugin ...

Sunday, June 12, 2011

Communities in Liferay Portal

Community is the group of users who shares the same interests. Each community have its own private and public pages in liferay portal.

Types of Communities:

There are 3 types of communities Liferay Portal. These are as follows-

  1. Open: Open Community allows users to join and leave a Community whenever they want to.

  2. Restricted: In Restricted Community user first have to make request for the membership. It means Restricted Community requires administrator or owner approval to add users to the community or to remove users from the community but users have the ability to leave the community.

  3. Private: In case of Private Community there is no way to join or make request for membership.Both  Community Owner and Community administrator can assign a user to the Community.


So basic difference between Restricted and Private Community is that, in case of Restricted Community membership is subject to administrator approval but in case of Private Community there is no way of joining the Community.

Thursday, June 9, 2011

Liferay Service Builder : Part 1 (Finder methods in liferay portal)

In liferay portal if we want to find records from table then we need finder methods. To create finder method we need to specify the finder tag in the service.xml file.

Assume that we have a database table named customer having fields like name, city, age etc. We want to find all the customers belonging to a particular city.

Following are the steps to create finder method for the above requirement-

1.  In the service.xml file add the following line after database columns declarations,

<finder name="City" return-type="Collection">
<finder-column name="city"></finder-column>
</finder>


Name – method name , a method named findByCity will be generated

Collection – return type

Finder column name – name of the corresponding column in the customer table

2.  Run the ant target "ant build-service". In the SampleUtil.java you will find the following method –

public static java.util.List<com.sample.model.Sample> findByCity(
java.lang.String city) throws com.liferay.portal.SystemException {
return getPersistence().findByCity(city);
}


3.  Copy the finder method from this class and paste it inside the SampleLocalServiceImpl class and modify the method definition as following

-       Remove the static modifier

-       Replace getPersistence() with SampleUtil.

4.  Run the target "ant build-service" again. After build finder will be available in your SampleLocalServiceUtil class.

List<Sample> customerList = SampleLocalServiceUtil.findByCity("cityname");

NOTE: Replace Sample with your EntityName.

Saturday, June 4, 2011

Adding a Plugin Portlet to Liferay Control Panel

Sometimes situations arises when we want to add our custom made plugin portlet to Liferay Control Panel.

To do so we need to made some entries in liferay-portlet.xml .  These are as follows-

1. control-panel-entry-category: It spefies the 'category' where your portlet will appear.

2. control-panel-entry-weight: weight determines the position among the other portlet listed in that category.

3. control-panel-entry-class: The name of a class that implements the ControlPanelEntry interface.

It’s not necessary to specify the class but depends on our requirement.

Here is an example-

<control-panel-entry-category>content</control-panel-entry-category>

<control-panel-entry-weight>100</control-panel-entry-weight>

NOTE- Make sure you provide a unique weight for your plugin portlet otherwise any liferay out of the box portlet with the same weight will override your portlet.