Total Pageviews

Saturday, August 27, 2011

A story of "Portlet" and "Servlet"

There are so many things which are very clear and understood but if someone ask, it become difficult to explain them in deep. The topic I am going to write today, is something like that. Hope, you'll enjoy reading it, as I am going to write this time full on text, no practical implementation.


The contents of servlets provide generally takes up the whole page in a browser (if you are not framing them), and portlets content are wrapped in a window and we can place multiple portlets on same page with one another and each can provide different content and functionality. A portlet behaves like a full fledged application. The portal can provide some house keeping functionality and secured single point of entries to all of the portlets on a page. 


lets see first some differences among portlets and servlets
  1. Servlets can provide complete web pages, whereas portlets only provide fragments. These fragments are then aggregated to form a complete web page by the portal.
  2. Portlets aren't allowed to generated HTML code that contains tags such as base, body, frame, frameset, head, html, or title. The iframe tag can be used with caution.
  3. The user cannot access a portlet directly using a URL in the way that a servlet is accessed. Instead, the URL points to the page containing all of the portlets on one page.
  4. Communication between the web client and the portlets is performed through the portal.
  5. Portlets can be provided with buttons or controls to manipulate the portlet's window states or portlet modes. 
  6. Multiple instances of a single portlet can be placed onto the same page.
  7. Portlets support persistent configuration and customization.
  8. Portlets also support user profile information.
  9. Portlets support two scopes within the session; application scope and portlet scope .
Here are some similarities
  1. Servlets and portlets are web based components that utilize Java for their implementation.
  2. Portlets are managed by a portlet container similar to a servlet container.
  3. Both of these components generate content, which can be static or dynamic.
  4. Both portlets and servlets have a lifecycle that is controlled by the container.
  5. The client/server model is used for both servlets and portlets.
  6. The packaging and deployment are essentially the same.
  7. The manner in which the classes are loaded and the class loaders that perform the work are also the same.
  8. Lifecycle management is similar.
  9. The Request and Response semantics are also similar.
Advantage of Servlets over portlets-
  1. Portlet aren't allowed to set the character set encoding of the response.
  2. Portlet also aren't allowed to set the HTTP headers on the response.
  3. Portlet cannot manipulate the URL of the client request to the portal.
Advantage of Portlets over Servlets-

  1. Portlet Modes :  Each portlet has a current mode, which indicates the function the portlet is performing.
  2. All JSR 168 compliant portals should support the View, Edit and Help modes.
  3. Window States :Window states indicate the amount of portal page space that will be assigned to a portlet.
  4. Portlet Preferences :Portlets can be configured to provide a custom view or behavior for different users.

Saturday, August 20, 2011

Creating a new category in Control Panel and Adding portlet in it


While development of any big portal, we need to customize control panel also. In such a case, its generally needed to make a new category in control panel and adding portlet in it. So, here are the steps, hope you'll find it helpful.

1. Override the class PortletCategoryKeys (in ext-impl\src\com\liferay\portal\util\PortletCategoryKeys.java)
Put the category in ALL array in the order you wish to appear your category.

2. Now add portlet in this category using the following entry in liferay-portlet-ext.xml file
here  portlet_id is the id of the portlet that you wish to add in our custom category. Specify the name of the category in <control-panel-entry-category> entry and sequence of portlet appearance in determined through <control-panel-entry-weight>. The higher the weight, upper will be the portlet(weight can also be in floating number).

3. Now an important point, we must enter the category name entry in language-ext.properties file, so that our category can be recognized, otherwise you'll get category name as "category.mycategory"
That's all I did, hope will work for you too.

Saturday, August 13, 2011

Writing Parameterized properties

Hi all,
Its quite a small thing, but very useful in live scenario.
Just two points-
write a property in language-ext.properties file as follows-
and now use it as follows.
for using more then one replacement, do as follows.
and use it as:
One key point is- 'x' is nothing but only a token placeholder for programmer understanding where the value will be inserted. The actual thing is {1} like tokens.
Hope this will help. Cheers !!!

Saturday, August 6, 2011

Using Liferay Services in VM using ServiceLocator

When developing custom themes, we need to use Liferay services in VM. Its quite easy but tricky. So, putting here a simple example-
Write following in init-custom.vm

Now you can use this service as follows:
where $myPlace is a group.


Hope this will help.