Showing posts with label window state. Show all posts
Showing posts with label window state. Show all posts

Monday, April 7, 2014

Introduction to JSR 168/Portlet Specification 1.0

Introduction:

Sun micro system introduced Java Portlet technology to the world. In the Technology world each and every technology has some specifications based on this different people will implemented the software. The requirement specification is called Application Programming Interface.

Coming to portlet technology all requirement specifications comes under JSR 168 standards.
JSR 168 is portlet specification defined by java community people based on this many people implemented portlet technologies.JSR 168 is called portlet 1.0 specification.

Many vendors have implemented the Portlet Technology specification namely Liferay, uPortal, Web logic Portals, Webspear Portals and Apache Jetspeed.

JSR 168 is starting version of portlet technology and then people was added more specification in JSR 286.

This portlet technology specification was defined the portlet lifecycle and its management in the portlet container. Portlet lifecycle is similar to servlet lifecycle.

We already know to run or manage servlet lifecycle we need servlet containers similarly we have portlet container which is responsible for manage lifecycle of portlet.

All these specification and portlet lifecycle and management was specified in JSR 168 and JSR 286 standers all vendors who implemented the portlet technology should follow the portlet specification.

JSR 168 Portlet Important Specifications
  • Provide Run time environment to run portlet i.e. define portlet container
  • Implement API between Portlet Containers and Portlets
  • Implement Mechanism to store transient and persistence data for portlet.
  • Define Portlet Lifecycle
  • Provide methods for easy deployments of portlets
  • Allow portlets run in other vendor portals which follows JSR 168 standards.
  • Run JSR 168 portlets as remote portlets using the Web Services for Remote Portlets (WSRP) protocol
Important Artifacts in JSR 168 specification
  1. Portal
  2. Portlet
  3. Portlet Container
  4. Portal Page
Portal

Portal is web application which provides content aggregation, personalization and single sign of from different sources. Portal consists of web pages and each page has dynamic and static content.

Portal Page:

Portlet page is part of portal and its simple a web page. In general web application page consist of one dynamic application but coming to portal page it consist of multiple dynamic application and static content all together is called portal page.

A portal page is an aggregation of dynamic content and static content we can say portal page is fragments of dynamic and static content served by portlet container. Each portal page has specific layout there all portlet applications are reside.

Example Diagram For portal Page


Portlet Container

Portlet container is responsible for manage the portlet lifecycle. Portlet container is similar to server container.

Portlet container is integrated with web server/application so that it will use http protocol to communicate with client and serve the content. Generally some application server has provision to inbuilt with portlet container to support run time environment to portlet.

Portlet

Portlet is fragment of dynamic content which reside in portal page. Similar to servlet, portlets are web components that are deployed inside of a container and generate dynamic content. On the technical side, a portlet is a class that implements the javax.portlet.Portlet interface and is packaged and deployed as a .war file inside of a portlet container

Portlet properties

  • Portlets are managed by specialized containers called portlet containers.
  • Portlets are server side component which generate the dynamic content.
  • Portlet have its own lifecycle which will be manage by portlet container
  • Portlet will be used request/response mechanism to interact with web client using http protocol.

How portlets are differed from Servlet
  • Generally in servlet web application each servlet will be referred by URL to invoke or access and each web page content will be served by one servlet but in portlets each page will be served by different  portlet and each portlet will have its own lifecycle and own URL pattern to execute.
  • Servlet will generate dynamic content which send to browser and it’s in single web page but portlet will server fragment of dynamic content and portal page is responsible to aggregate content from different portlet to generate whole page.

Portlet life cycle

As we already know each portlet has it own lifecycle and which will be managed by portlet container. According to the JSR 168 standard portlet have three lifecycle stages.

init:

 Initialize the portlet and put the portlet into service

Handle requests:

Process different kinds of action- and render-requests

Destroy:

Put portlet out of service

Theoretically we have 3 lifecycle stages in portlets and these will be implemented via portlet interface. Portlet interface is implemented in jax.portlet package by Sun Microsystems.

Every portlet that should implement the portlet interface or it should extend the class that already implemented the portlet interface.

As we know portlet have three lifecycle staged and the following are interface methods which handle portlet lifecycle cycle in portlet implementation.

init(PortletConfig config):

This method is initialize the portlet and this will be called only once when portlet is instantiated, we can say when we drag and drop portlet in page.

If any necessary functionality required at initial time of portlet we will use this method and write code here. It is similar to servlet init method. This method can be used to create expensive objects/resources used by the portlet.

processAction(ActionRequest request, ActionResponse response):

When user is requested to server then portlet will execute process action method.
This method will notify the portlet that used has triggered an action this portlet. , a portlet can issue a redirect, change its portlet mode or window state, modify its persistent state, or set render parameters.

render(RenderRequest request, RenderResponse response):

Render method will generate content and that will be send to web client.
In the portal page we have many portlet we have triggered action in one portlet then all portlet will be executed render method to aggregate dynamic content. The portlet can produce markup that may depend on the portlet mode or window state, render parameters, request attributes, persistent state, session data, or backend data.

destroy ():

Indicate to the portlet the life cycle's end. This method allows the portlet to free up resources and update any persistent data that belongs to this portlet.

Note:

In the portlet lifecycle for each action or request the final method is render method. Render method will be called for every time to aggregate content or produce content.

Generally portlet have different URL to call these methods like Action URL and Render URL.
Action URL will execute portlet porcessAction(----) method and then it will be execute the render(----) method.

Render URL will execute the portlet render (---) method only.



Portlet Characteristics

Portlet have addition Characteristics when we compare with servlet.

Portlet Widow States:

Portlet has different window states. Window state specifies how portlet will look in the page .Window state decides how much space will be accommodated in portlet page.

The following are important window states as for JSR 168 Standards.

Maximized:

When portlet state is decided as Maximized then entire page only one portlet is visible.
Generally we will use this state after perform some action then we will make widow state is Maximized.

Normal:

Specified that is portlet may share the page with other portlets. This is the default window state.

Minimized:

Portlet should only render minimal output or no output at all.

Portlet Modes:

Portlet mode specifies that the function will be performed by portlet.
Generally following are the portlet modes that each portlet should support as for JSR 168 standards.

View:

 This view mode is when portlet is access or render then portlet is in view mode and this is default mode for portlet.

Edit:

Edit mode will be used to edit some portlet functionality and generally we wil use this mode for administrator to modify or edit something.

Help:

This will used to provide content to end user about portlet i.e how to use and access portlet like help information.

Persistent storage for preferences:

Portlets provide a PortletPreferences object for storing user preferences. These preferences are stored in a persistent data store, so they will be available across server restarts. As a developer, you don't have to worry about the actual implementation of how it is stored.

Author

Monday, November 11, 2013

Working with Liferay URLs

Working with Liferay URLs


In liferay development we have many options to create liferay URLs i.e.
Render URL, Action URL and Resource URL.
We have many ways to create liferay URL in development the following are the ways to create URLs

  1. Using tag library
  2. Using complete java classes and java objects
  3. Using Java script


Using Tag Library:

Liferay provide build in tag library from that we can create liferay URLs.
We have two tag libraries from which we can create URLs

  • Portlet tag library
  • Liferay Portlet tag library.


Portlet Tag Library :

Portlet tag library is stand tag library for every portal means it’s just JSR 168 and JSR 286 standard tag library.

To make use of this tag library in jsp page we need to use following tag.


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


Render URL creation:



<portlet:renderURL var="simpleDialogIframeExample" windowState="<%=LiferayWindowState.POP_UP.toString()%>">
<portlet:param name="mvcPath" value="/html/alloyuidialog/iframe_alloyui_dialog_example.jsp"/>
</portlet:renderURL>


The following are important attribute for tag:

var : This is variable name so that we can reference URL by this name
Window state: This is liferay window state like normal. Maximized ,minimized and pop_up.
portlet mode : this is mode of portlet view or edit
copyCurrentRenderParameters: This is whether you want copy all render parameters
If you want add more addition parameters we should use another tag called <portlet:param/>
This is used to add more parameters or custom parameters

Finally this tag converted and the URL like following

For example my portlet Name:  LiferayAlloyUIDialogportlet
I am creating Render URL in view.jsp page for this portlet
Then finally URL look like this in browser address bar its simple query string




p_p_id: current portlet id
p_p_state: window sate
p_p_mode: portlet mode either view/edit
p_p_lifecycle: this is life cycle of portlet  0/1/2
0: render phase or render URL
1: action phase or action URL
2: server resource URL
mvcPath: this is another parameter which we passed from <portlet:param/>  tag

Note:

Similarly all URL have same parameters like above when we create URL from portlet tag library

Examples for URLs created from portlet tag library:

Render URL:

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<portlet:renderURL var="simpleDialog" windowState="normal">
<portlet:param name="mvcPath" value="/html/alloyuidialog/simple_alloyui_dialog.jsp"/>
</portlet:renderURL>

Action URL:

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<portlet:actionURL var="iFrmedilogActionURL" windowState="<%=LiferayWindowState.POP_UP.toString()%>">
<portlet:param name="<%=ActionRequest.ACTION_NAME%>" value="getActionMessageForSimpleDialog"/>
</portlet:actionURL>

Resource URL:

<portlet:resourceURL var="feedBackResourceURL" id="view.jsp" escapeXml="false" />

Note:

With this tag library we can create URL for only current portlet .means where jsp page is located in portlet for that particular portlet only we can create.

Liferay Portlet Tag library:

This is another tag library which is from liferay by this we can create URLs but the difference between standard tab library and liferay tag library is  we can create URL for other portlet also.
Means if you work with PortletA in portletA JSP page we can create URL for PortletB. This is using in some scenarios where you want pass some parameters form portletA to portletB.
To make use of this library we need to add following tag library in jsp page


<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>


Example for create Liferay URLs from Liferay Portlet Tag Library:

For example I want create RenderURL for portlet 47 means this is document library portlet

The following is example

<liferay-portlet:renderURL portletName="47" var="openPortletURL" plid="<%=themeDisplay.getPlid()%>"  varImpl="openPortletURL" windowState="<%=LiferayWindowState.POP_UP.toString()%>">
</liferay-portlet:renderURL>

Important Attributes:

portletName: the name of portlet  for which you going to  create URL.
plid :  In which page your portllet is reside. Means its layout id
var : This is variable name so that we can reference URL by this name
Window state: This is liferay window state like normal. maximized, minimized and pop_up.
Portlet Mode: this is mode of portlet view or edit
copyCurrentRenderParameters: This is whether you want copy all render parameters or not means if you make this tru parameter will available in complete request cycle.

Finally URL likes this:




p_p_id: current portlet id
p_p_state: windiow sate
p_p_mode: portlet mode either view/edit
p_p_lifecycle: this is life cycle of portlet
0: render phase or render URL
1: action phase or action URL
2: server resource URL
To pass custom parameters to this URL we need to use <liferay-portlet:param/> tag

Note:

If we not pass portletName and plid then URL will be created for current portlet.

Examples for create Liferay URLs from Liferay Portlet Tag Library:

Render URL:


<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>
<liferay-portlet:renderURL portletName="47"   var="openPortletURL" plid="<%=themeDisplay.getPlid()%>"  varImpl="openPortletURL" windowState="<%=LiferayWindowState.POP_UP.toString()%>">
<liferay-portlet:param name="name" value="meera"/>
</liferay-portlet:renderURL>

Action URL:

<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>
<liferay-portlet:actionURL portletName="47"   var="actionURL" plid="<%=themeDisplay.getPlid()%>"  varImpl="openPortletURL" windowState="<%=LiferayWindowState.MAXIMIZED.toString()%>">
<liferay-portlet:param name="name" value="meera"/>
</liferay-portlet:actionURL>

Resource URL:

<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>
<liferay-portlet:resourceURL   var="resourceURL" plid="<%=themeDisplay.getPlid()%>"  varImpl="openPortletURL" windowState="<%=LiferayWindowState.MAXIMIZED.toString()%>">
<liferay-portlet:param name="name" value="meera"/>
</liferay-portlet:resourceURL>

Using complete java classes and java objects

  • Create From renderResponse object
  • PortletURLFactoryUtil Class


Create From renderResponse object:

We can create URLs from render response object this is implicit variable we can directly us this. To make it available we need add following tag in jsp page then we can use renderResponse object in jsp page


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


The following is sample code:

Render URL:


<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<portlet:defineObjects />
<%@page import="javax.portlet.PortletURL"%>
<%
PortletURL myRenderURL=renderResponse.createRenderURL();
myRenderURL.setWindowState(LiferayWindowState.MINIMIZED);
myRenderURL.setParameter("name", "meera");
%>


Action URL:


<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<portlet:defineObjects />
<%@page import="javax.portlet.PortletURL"%>

<%

PortletURL myActionURL=renderResponse.createActionURL();
myActionURL.setWindowState(LiferayWindowState.MAXIMIZED);
myActionURL.setParameter("name", "meera");

%>


Resource URL:


<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<portlet:defineObjects />
<%@page import="javax.portlet.ResourceURL"%>

<%

ResourceURL myReourceURL=renderResponse.createResourceURL();
myReourceURL.setResourceID("myResource");
myReourceURL.setParameter("name", "meera");

%>


Note: from renderResponse we can create URLs for only current portlet.

PortletURLFactoryUtil Class:

PortletURLFactoryUtil is util class from which we can create liferay URLs. Here we can create URL to other portlet also. Means from portletA we can create URL for portletB.

The following is examples:

Render URL:


<%@page import="com.liferay.portal.kernel.portlet.LiferayPortletURL"%>
<%@page import="com.liferay.portlet.PortletURLFactoryUtil"%>
<%
LiferayPortletURL myRenderURL=PortletURLFactoryUtil.create(renderRequest, "47", themeDisplay.getPlid(), "0");
myRenderURL.setWindowState(LiferayWindowState.MINIMIZED);
myRenderURL.setParameter("name", "meera");
%>


Action URL:


<%@page import="com.liferay.portal.kernel.portlet.LiferayPortletURL"%>
<%@page import="com.liferay.portlet.PortletURLFactoryUtil"%>
<%
LiferayPortletURL myActionURL=PortletURLFactoryUtil.create(renderRequest, "47", themeDisplay.getPlid(), "1");
myActionURL.setWindowState(LiferayWindowState.MAXIMIZED);
myActionURL.setParameter("name", "meera");
%>


Resource URL:


<%@page import="com.liferay.portal.kernel.portlet.LiferayPortletURL"%>
<%@page import="com.liferay.portlet.PortletURLFactoryUtil"%>
<%
LiferayPortletURL myReourceURL=PortletURLFactoryUtil.create(renderRequest, "47", themeDisplay.getPlid(), "2");
myReourceURL.setParameter("name", "meera");
%>


Finding portlet name or p_p_id:

Go through following link and find How to find portlet Id or p_p_id or portlet Name
section.


Using Java script:

We can also create liferay URL from java script in liferay. Liferay provides java script module called liferay-portlet-url from this we can create URLs in java script
First we need to use AUI tag library then we have to use AUI use method to load liferay-portlet-url   module


<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
<aui:script>
AUI().use('aui-base','liferay-portlet-url','aui-node', function(A) {

});

</aui:script>

Examples:

Render URL:



<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
<aui:script>
AUI().use('aui-base','liferay-portlet-url','aui-node', function(A) {
var myRenderURL =Liferay.PortletURL.createRenderURL();
myRenderURL.setPortletId('47') 
myRenderURL.setWindowState('pop_up');

});
</aui:script>


Action URL:



<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
<aui:script>
AUI().use('aui-base','liferay-portlet-url','aui-node', function(A) {
var myActionURL =Liferay.PortletURL.createActionURL();
myActionURL.setPortletId('47') 
myActionURL.setWindowState('MAXIMIZED');  
myActionURL.setParameter("name","meera");
});
</aui:script>



Resource URL:


 
<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
<aui:script>
AUI().use('aui-base','liferay-portlet-url','aui-node', function(A) {
var myResourceURL =Liferay.PortletURL.createResourceURL();
 myResourceURL.setResourceId('someid');
 myResourceURL.setParameter("name","meera");});
</aui:script>




Note: all these code snippets use in jsp pages only.

Important points:

  • We can create Liferay URLs in different ways  from tag library java classes and java script.
  • From render response and portlet tag library we can create URL for only current portlet.
  • From PortletURLFactoryUtil class and liferay-portlet tag library we can create URLs to other portlets means from one portlet to other portlet we can create .Here main attributes are portletName and plid. Plid is page layout id.
  • When we create any URL finally url converted into normal URL query string which we can see in browser address bar.
  • Liferay portlet have different lifecycles action render and resource each phase we represend as p_p_lifecycle attribute.  1 for action phase, 0 for render phase and 2 for recourse phase.
  • Liferay portlet have edit and view mode.
  • When create URL using java script we have to liferay-portlet-url    module this module can be loaded by aui use method.


Author:
Meera Prince









Recent Posts

Recent Posts Widget

Popular Posts