|
|
81.Hook vs EXT vs Portlet:?
Liferay provides 3 ways to extend the functionality of a Liferay portal.They are Hook,EXT and Portlets.
Hook:
Liferay portal comes with a bundle where all the default built in portlets exist. Typically if any customization required in terms of JSP (UI) and portal properties,we need to go by Hook implementation.A hook plugin is always combined with a portlet plugin
Hook is supported by hot deployment.
Scenarios:
- When you have to perform a custom action on portal startup.
- When you have to perform a custom action on user login
- When you need to overwrite or extend portal JSPs
- When you need to modify portal properties
- When you need to replace a portal service with your own implementation.
EXT:
Liferay EXT Plugins are the most powerful way to extend the portal functionality. If any customization required in the core level classes then it can be done through EXT. But here in EXT, restart would be required.The Liferay EXT Environment is where you would ideally make changes to the portal itself. In other words, this is where you customize or “extend” the portal.
When you have to upgrade, you will have a tough time sorting out what is out-of-the-box and what is customized (if you make changes to portal source directly).EXT Environment keeps things separate.
Example: LDAP users and user groups import modification.
Note: EXT Plugins should be used only in case the portal functionality cannot be extended using Portlet of Hooks.
Scenarios:
- Customizations to portal.properties (that is not supported by Hook Plugins)
- Customizations of the Liferay beans declared in Liferay's Spring files
- Customizing and making changes to the Struts Actions for portal
Portlets:
New portlets in liferay market place are SpeedReadPortlet and MyIPPortlet.
Portlet lifecycle:
- init(PortletConfig config):initializes the portlet.It is called once, immediately after a new portlet instance is created.It can be used to perform startup tasks and is akin to a servlets init method.
PortletConfig represents read-only configuration data, specified in a portlet's descriptor file, portlet.xml
- processAction(ActionRequest request, ActionResponse response):
It is called in response to a user action such as clicking a hyperlink or submitting a form.In this method, a portlet may invoke business logic components, such as JavaBeans, to accomplish its goal. In processAction, a portlet may modify its own state as well as persistent information about a portlet.
- render(RenderRequest request, RenderResponse response):
This method follows processAction() in the chain of lifecycle methods.Render generates the markup that will be made accessible to the portal user. It mainly render the view in term of JSP/HTML code and show into the respective portlet.
- destroy():
It is called just before a portlet is garbage collected and provides a last chance to free up portlet resources.
82.Page Rendering in Liferay:
- Request comes in through MainServlet.
Various attributes are stored in the session and request. The request attribute WebKeys.CURRENT_URL holds the currently requested path (stripped of protocol,host, and port).
- The "service pre action" handler com.liferay.portal.events.ServicePreAction(servicePre() method) is called, where the layout and theme to display are determined. The following values are stored as a below request attributes.
WebKeys.LAYOUT key : To store current Layout.
WebKeys.LAYOUTS key : The other available layouts.
WebKeys.THEME key : To store the theme to display
WebKeys.COLOR_SCHEME key: color scheme to use .
The theme and color scheme are usually determined by querying the layout once it has been determined.
- Struts is called to handle the request, and Liferay uses the custom Struts request processor com.liferay.portal.struts.PortalRequestProcessor.
The PortalRequestProcessor.getLastPath() method computes the last path visited, and supplies a default path for the first entry into the portal. The default path upon entry into the portal is ://:/portal/layout.
- This initial request for /portal/layout is handled by com.liferay.portal.action.LayoutAction. /html/common/themes/portal.jsp is the "top level" display page.
- It selects the portal_normal.jsp or portal_pop_up.jsp based on the current state of the theme's display, and includes it using the custom tag, implemented by com.liferay.taglib.theme.IncludeTag, which in turn calls com.liferay.taglib.util.ThemeUtil.include() method.
- Eventually, for each portlet, the method com.liferay.portal.util.PortalUtil.renderPortlet() gets called, which calls /portal/portal-web/docroot/html/portal/render_portlet.jsp to render the contents of an individual portlet.
- That in turn calls /portal/portal-web/docroot/html/common/themes/portlet.jsp, which ends up calling /portal/portal-web/docroot/html/common/themes/portlet_content.jsp
83.VIEW mode vs EDIT mode of a portlet:?
The modes of a portlet are typically related to the types of operations a user can perform on the portlet.
A view mode is where users are allowed to do read only operations, whereas in edit mode user can add/update the data in the portlet.
Edit mode is the configuration options that are displayed when the edit button is clicked on the portlet.
Each portlet mode has a method which handles it:
doView(), doEdit(), doHelp().
One needs to override the doView(RenderRequest renderRequest, RenderResponse renderResponse) method after overriding the MVCPortlet class inorder to write a portlet.
84.Request flow in Liferay:
- The initial request comes into the portal server from the browser, and hits the service() method of the classcom.liferay.portal.servlet.MainServlet. Here, a variety of objects are created and added to the request for use by code downstream (such as company Id, user objects, etc.)
- Code passes through the servicePre() method of the class com.liferay.portal.events.ServicePreAction. Here is where the ThemeDisplay object is created and populated for downstream code use.
- The theme infrastucture code will call into the class com.liferay.taglib.util.ThemeUtil to render the content of a theme. It will call either the mehod includeJSP() to include JSP rendered content, or inclu deVM() to include Velocity rendered content.
- When using a Velocity based theme, the request will flow thru the class com.liferay.portal.velocity.VelocityVariablesand the method insertVariables(). That method is where various Velocity variables for use by the theme system is added to the Velocity context.
- For each column in the page's layout, the PortletColumnLogic class processes each portlet using the processContent()method. In this method, the HTML that surrounds every portlet is generated. Further processing is then delegated to the RuntimePortletUtil via the processPortlet() method. Then on to the actual rendering...
- An individual portlet is rendered by the render_portlet.jsp code located (in Tomcat) in the webapps/ROOT/html/portaldirectory. This JSP is called to render each portlet on the page. Debug code can be added to this file to see exactly what is going on just before and just after the code in your custom portlet is executed.
- As will be found by looking through the JSP code, render_portlet.jsp uses InvokerPortletImpl's render() method to render portlets. The primary function of this method is to check if a portlet's expiration-cache has been set or has expired. If the expiration-cache has been set, InvokerPortletImpl then checks whether the portlet's most recently cached content is fresh enough to us
85.Tools and frameworks used by Liferay:?
Struts, log4j, ANT, Freemarker, EHCache, Hibernate, Velocity, Spring, slf4j, Ajx,html, JavaScript, Java, CSS.
86.Do we need external JDK in addition to Bundled JRE?
The JDK is required to create liferay portlets but the JRE is required for running the portlets
87.Liferay Theme:?
Liferay themes are the way to customize look and feel of a liferay portal page.Themes are hot deployable plugins unique to a site served by the portal.The themes are extendable components that can be deployed separately on a portal and each page on the portal can choose a different theme (if required).
88.Custom theme:?
Custom themes are created by layering your customizations on top of one of Liferay’s built-in themes.The _diffs folder that’s created inside the docroot directory of your theme is important; this is where you place your theme’s code. The _diffs folder must mirror the parent theme’s directory structure. Since you’ll only customize the parts of your theme that differ from the parent theme, place only the folders and files you’ll customize there
The other folders inside docroot were copied over from the parent theme in your Liferay bundle when you deployed your theme.
For example, to customize the navigation, copynavigation.vm from deep-blue-theme/docroot/templates/navigation.vm into the deep-blue-theme/docroot/_diffs/templates folder
89.Theme Inheritance:?
By default, themes are based on the _styled theme. In build.xml, the theme.parent property determines the theme your theme inherits its styling from.
90.Velocity Templates:?
The places in Liferay that support Velocity templating are:
- Theme
- layout templates
- CMS Content Templates
91.Liferay Portal Instance:
Liferay Portal allows you to run more than one portal instance on a single server. The Portal Instances page of the control panel lets you manage these instances. Data for each portal instance are kept separate. All portal data, however, is kept in the same database.
Each portal instance requires its own domain name. Liferay will direct users to the proper portal instance based on this domain name. So before you configure an instance, we need to configure its domain name in our network first. When we are ready to add an instance, click the Instances tab - > Add button.
Two different domain names on Liferay:
Single instance of Liferay Portal supports hosting of two or more domain names via communities(sites).
Go to control panel -> Site settings -> we can provide the site URL
92.Liferay 6.1 New features:?
- The Sites concept has been introduced.
- Setup wizard: To ease the first time configuration of a portal(and its associated database),when starting a new instance of a Liferay, the optional setup wizard will prompt for you. No more mucking about with portal-ext.properties.
- Marketplace support.
- Content management improvements: Introducing inline drag/drop structure editing, internationalized web content titles, preloading of structures on template creation
- Search improvements: Including users in search results
- Unification of [Document library]+[Image Gallery]= [Documents and Media]
- Media playback facility: Audios and videos can be captured and played back within Liferay.
93.Liferay 6.2 new features:?
- Liferay is now upgraded to Alloy 2.0 which will give entire new look to Liferay. Liferay 6.2 uses Twitter® Bootstrap-based theming for a slick, vibrant look and feel with instant access to the Twitter® Bootstrap (Bootstrap) theme library.
- Bootstrap is a front end framework used for faster and easier web development.
- New look and feel for control panel.It is divided in to 4 main columns Users, Sites , Apps and Configuration
- Dockbar UI got changed and categorized in new format.
- New template editor with Auto Complete.
94.Liferay Plugin SDK:?
The Liferay Plugins SDK is a development environment that helps in the development of all types of plugins for Liferay including:
- Portlets
- Themes
- Layout templates
95.Structures in Content Management System:?
You can use Structures to define which fields are available to users when they create content. These can be coupled with Templates that define how to display that content.
Structures not only improve manageability for the administrator, they also make it much easier for users to quickly add content.
Structures give you the ability to provide a format for your content so your users know what needs to be entered to have a complete article.
You create a structure by adding form controls such as text fields, text boxes, text areas (HTML), check boxes, select boxes and multi-selection lists. Also you can add specialized, Liferay-specific application fields such as an Image Uploader and Documents and Media right onto the structure. Template would be responsible to display the content in specific format defined in structure.
- Create a structure and then template.
- select the created structure and template while creating web content.
- While creating a template you need to add the script for playing videos.
<script src="http://releases.flowplayer.org/js/flowplayer-3.2.9.min.js">
player
" style="width:500px;height:320px;display:block">
<script language="JavaScript">
flashembed("player", "http://releases.flowplayer.org/swf/flowplayer-3.2.10.swf", {
config: {
clip: 'http://localhost:8080$video_link.getData()',
plugins: {
controls: null
}
}
});
//here ‘video_link’ is the structure name
- Select template type as VM.
96.Create Liferay Portlet using Spring MVC:?
Ref: http://www.opensource-techblog.com/2012/09/spring-mvc-portlet-in-liferay.html
PortletMVCFramework is a mirror image of web mvc framework in spring.
Step1: create a portlet using Liferay plugin sdk.
Step2: open portlet.xml file under WEB_INF folder and replace com.liferay.util.bridges.mvc.MVCPortlet with org.springframework.web.portlet.DispatcherPortlet.
Here DispatcherPortlet is the central dispatcher(front end controller) for use within the Portlet MVC framework.
A web application can define any number of DispatcherPortlets. Each portlet will operate in its own namespace, loading its own application context with mappings, handlers, etc. Only the root application context as loaded by ContextLoaderListener
Step3: Create spring application context file for portlet.
Please create a file -portlet.xml under WEB_INF folder where is the name given for element in portlet.xml.
Here sampleportlet-portlet.xml file is created where sampleportlet is portlet name.
Step4: Mapping the above created context file to the portlet.
We will point it through init-param in portlet.xml file. param name will be "contextConfigLocation" and its value will the location of spring application context file
Step5: Defined ViewRenderServlet in web.xml file.
ViewRendererServlet is a bridge servlet, mainly for the Portlet MVC support.For usage with Portlets, this Servlet is necessary to force the portlet container to convert the PortletRequest to a ServletRequest, which it has to do when including a resource via the PortletRequestDispatcher.
The actual mapping of the bridge servlet is configurable in the DispatcherPortlet, via a "viewRendererUrl" property. The default is "/WEB-INF/servlet/view", which is just available for internal resource dispatching.
Step6: Configuring view.
DispatcherPortlet will take the help of ViewResolver to choose the view(here JSP)
Configure the view(through ViewResolver) in spring application context file (sampleportlet-portlet.xml).
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/jsp/SamplePortlet/" />
<property name="suffix" value=".jsp" />
</bean>
Step7: Create Request handler(controller).Here SamplePortletController.java
Below is the controller class code snippet.
@Controller(value="SamplePortletController")//
@RequestMapping("VIEW") //to inform DispatacherPortlet that this controller will support VIEW mode
public class SamplePortletController {
@RenderMapping
public String loadPortletData(RenderRequest request,RenderResponse response, Model model){
return "view";
}
}
@RenderMapping annotation tell that this is a default render method. It means whenever we place this portlet, it will render this method.
If you need to call specific render method instead of default render method then follow the below steps.
a.create a method in controller and annotate with the following.
@RenderMapping(params = "action=getIt")
b. In view.jsp code should be as follows.
The RenderRequest represents the request sent to the portlet to handle a render. It extends the PortletRequest interface to provide render request information to portlets.
An ActionRequest is valid during the action processing phase of the portlet. During this phase, the portlet hasn't completely decided how it is going to render itself, be it minimized, maximized, in edit mode or in veiw mode, etc
97.?
98.?
99.?
100.?
|