Quantcast
Channel: It's all about Java and Liferay
Viewing all 12 articles
Browse latest View live

Access Liferay Service & Util and Custom Portlet Service & Util Class in Velocity Template

$
0
0
Here are the steps to access services and util class of custom portlet in velocity template.

1) Make sure the services and util class which you want to access are available inside tomcat/lib/ext.

2) In order to access services you need to place below property inside portal-ext.

journal.template.velocity.restricted.variables=
By default this property will be like this
journal.template.velocity.restricted.variables=serviceLocator

Which means you wont be able to access serviceLocator inside velocity template.
So make sure before you access any service inside velocity template change this property to
journal.template.velocity.restricted.variables=

3) Access services using findService Method of Custom Portlet in Velocity.

#set ($customLocalService = $serviceLocator.findService('my-profile-portlet', 'com.sample.portlet.myprofile.service.MyProfileDataLocalService'))

#set ($number=$customLocalService.getMyProfileDatasCount())

$number

Normally we use findService(serviceName) method to access Liferay service.
But to access custom portlet service we have to use findService(contextName,ServiceName).

findService(serviceName) will search at the portal level and findService(servletContextName , serviceName) will search at specified portlet level.

4) Access Liferay Services using findService Method in Velocity

#set ($userLocalService= $serviceLocator.findService("com.liferay.portal.service.UserLocalService"))
#set ($user = $userLocalService.getUserById($request.get("theme-display").get("user-id")))
#set ($emailAddress = $user.getEmailAddress())

5) Access util class using  findUtil Method for inbuilt Util of Liferay

#set ($journalContentUtil = $utiLocator.findUtil("com.liferay.portlet.journalcontent.util.JournalContentUtil"))

6) Access util Class of Custom Portlet in Velocity refer below link

http://www.liferay.com/web/raymond.auge/blog/-/blogs/2245146

Liferay Eclipse Setup

$
0
0

Liferay Folder Structure


1. create Liferay folder in C drive
2. unzip Liferay tomcat 6.0 bundle (liferay-portal-tomcat-6.0-5.2.3.zip) to Liferay folder
3. unzip Liferay plugin SDK (liferay-plugins-sdk-5.2.3.zip) to Liferay/plugins folder
4. unzip Liferay EXT (liferay-portal-ext-5.2.3.zip) to Liferay/EXT folder
5. unzip Liferay Portal Source (liferay-portal-src-5.2.3.zip) to Liferay/portal folder

After above steps folder structure will as bellow

      c:\Liferay
            - data
            - deploy
            - EXT
            - license
            - plugins
- portal
            - tomact-6.0.18


Eclipse Setup

 
1. Start Eclipse and create three JAVA projects (plugins, EXT, Portal) as follow:

 
2. Create plugins project
  • Create New JAVA Project
  • Goto > File > New > Java Project
  • Project Name > plugins
  • Select "Create Project from existing Source"
  • Click on browse and select directory plugins (liferay-plugins-sdk-5.2.3)
  • Click Finish
3. Create EXT project
  • Create New JAVA Project
  • Goto > File > New > Java Project
  • Project Name > EXT
  • Select "Create Project from existing Source"
  • Click on browse and select directory EXT (liferay-portal-ext-5.2.3)
  • Click Finish
4. Create Portal project
  • Create New JAVA Project
  • Goto > File > New > Java Project
  • Project Name > portal
  • Select "Create Project from existing Source"
  • Click on browse and select directory Portal (liferay-portal-src-5.2.3)
  • Click Finish

5. Run Configuration Settings
 
  • Open "Run Configurations..." under the Run Menu
  • Under Java Applications node in the tree, right click and "New"
  • Click on New_Configuration and change Name: Liferay
  • On Main tab, select the portal source code project or your Plgins project
  • In the Main class put org.apache.catalina.startup.Bootstrap, don't check any check boxes
  • Go to Arguments tab, in the Program arguments type: start
  • In VM arguments put like:
-Xmx512m
-XX:PermSize=32m
-XX:MaxPermSize=160m
-Dfile.encoding=UTF8
-Duser.timezone=GMT
-Dcatalina.base=-Xmx512m
-Djava.security.auth.login.config=C:/Liferay/tomcat-6.0.18/conf/jaas.config
-Dcatalina.base=C:/Liferay/tomcat-6.0.18
-Dcatalina.home=C:/Liferay/tomcat-6.0.18
-Djava.io.tmpdir=C:/Liferay/tomcat-6.0.18/temp

  • In Classpath tab, remove ALL User entries, do NOT remove the JRE System library
  • Select User Entries and "Add External Jars", find the bootstrap.jar file from the ${tomcat-root-folder}/bin folder and add only that one
  • In the Source tab, select any related Java project (EXT, Plugins, Portal), but also the main project. For example, if you want to also debug a plugin, add it's source path here
  • Under Common tab check Run (if we want debugging then check Debug)
  • Apply all changes
  • Run Liferay from Run Icon (View output on console)



LDAP Configuration with Liferay

$
0
0

 OPEN LDAP SERVER CONFIGURATION FOR WINDOWS

 

Softwares Used:

OpenLDAP (Windows edition)
LDAP Browsers(Apache DS,Jxplorer, LDAPsoft admin tools, Softerra LDAP admin etc)


Download Softwares:

1. You can download openLDAP windows edition from the following location:
2. you can download browsers from the locations given below:
Softerra LDAP admin: http://www.ldapadministrator.com/download.htm


Installing openLDAP:

1. Follow the instructions and choose your host as “localhost” or an “IP address”
2. Choose the port and SSL-port as you may want to use or can let it by default to 389 and 636 respectively.
3. Select a database for directory you want to use: BDB or LDAP (we have used BDB i.e berkely’s DB)
4. NEXT -> choose a password for your root directory, by default it would be “secret
5. NEXT-> install-> Finish.

 Using an LDAP Browser:

As We have used “LDAPsoft LDAP admin”
1. Start the server using by clicking on the slapd.exewhere OpenLDAP is installed
2. Install LDAPsoft LDAP admin
3. Open “LDAPsoft LDAP admin” and create new connection to LDAP.
4. Specify the connection name - it could be any friendly name you may want to use
5. Specify the Hostname as “localhost” or “IP Address” as set at the time of installing OpenLDAP
6. Specify the port you are using for LDAP
7. Specify the Base DN as “dc=maxcrc,dc=com” or you may choose to click on “Fetch Base DNs” button to automatically fetch the Base DNs
9. Got to NEXT and select “Simple Authentication” method. For this, you will be needed to provide Bind DN and Password which would be “cn=Manager, dc=maxcrc, dc=com” and “secret” respectively. The Bind DN can also be populated by clicking on the button, which is on the right hand side of the Bind DN text field.
12. NEXT->Finish.

Now you have a complete connection with  openLDAP and you can create your own OUs and CNs.


How To Configure OPENLDAP in Liferay 

  1. Go to the Control Panel in Liferay 6 EE .
  2. Control Panel ---> Settings
  3. From the Right Side pannel Select the Configuration---> Authenticaion

After Clicking on the Authentication it will open different Options and Select LDAP on it.

Click on the Add from LDAP Servers

ServerName: Give any name
Default Values : Select open ldap


Fill all details as shown in image.
In Credentials : secret


After clicking on the Test LDAP Connection you will popup as shown in image.

USERS

Keep all the field as it is .

Just remove the text from the Group field at last before test ldap user button..
So, keep the Group field blank.

After clicking on the Test Ldap User button the popup will be displayed of the available users as shown in images below


In the Snapshot you will be able to see the users are displayed that we configured in OpenLDAP(Refer Last image in which it is shown the user that we configured in OpenLDAP Using Browser)


 Structure of LDAP with Apache DS





Congratulations, You have DONE with LDAP !!!!!!!

Redirect to Static page in liferay within a single portlet

$
0
0
In Liferay most of time happens with us that after submitting the form we want to redirect it to some other page.

Now it's not difficult any more.

Please check below code.It will help you to redirect to the Static page as you are aspecting in liferay.
String portletName = (String)actionRequest.getAttribute(WebKeys.PORTLET_ID);

ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

PortletURL redirectURL = PortletURLFactoryUtil.create(PortalUtil.getHttpServletRequest(actionRequest),
portletName,
themeDisplay.getLayout().getPlid(), PortletRequest.RENDER_PHASE);

redirectURL.setParameter("jspPage", "your jsp path");

actionResponse.sendRedirect(redirectURL.toString()); 
Congratulations, You have DONE NOW !!!!!!!

Connecting to different database using Liferay Service Builder

$
0
0
Generally we guys used to connect with the liferay default Database.
We also have requirement that Client wants there Data on Separate Schema or Separate DB.
But In Liferay how we can connect with different DB?

Don't Worry guys your problem is now solved.

Just Follow some steps as below :-

1) In Service.xml define the datasource, session-factory,transcation-manager within the Entity Definition as follows:-


test



......
......



2) Create a new file ext-spring.xml under WEB-INF/src/META-INF dir.














































3) And one more thing don't forget, pointing to the new DB.
    So the portal-ext.properties will look like as below :-
jdbc.default.url=jdbc\:mysql\://localhost/lportal?useUnicode\=true&characterEncoding\=UTF-8&useFastDateParsing\=false
jdbc.default.driverClassName=com.mysql.jdbc.Driver
jdbc.default.username=root
jdbc.default.password=root

jdbc.test.driverClassName=com.mysql.jdbc.Driver
jdbc.test.url=jdbc:mysql://localhost/anotherDatabaseName?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
jdbc.test.username=root
jdbc.test.password=root

4) Final Step Build service with the command ant build-service.

Congratulations,Your work is done !!!!!!!!!!

Deploying Ext in Liferay 6

$
0
0
On Deploying EXT, We face the problem that our changes are not getting reflected.

I seen people in liferay forums continuously asking for the same.

It is not perfect but will work in the case ,if you can't execute the command ant direct-deploy and want to execute ant deploy command.

The following steps you have to follow in order to redeploy the EXT Portlet

My Portlet name is Alert-ext so I am referring with this name in the below steps :-

1) Stop the Server
2) put ext-redeploy-6.0.5.jar in tomcat-6.0.29/Webapps/ROOT/WEB-INF/lib/
3) Delete the Alert-ext portlet from the webapps folder if in case you are redeploying
4) Remove ext-Alert-ext-service.jar from the tomcat-6.0.29\lib\ext
5) Remove all the *-ext.xml from the path tomcat-6.0.29\webapps\ROOT\WEB-INF except struts-config-ext.xml
6) Remove all the jar file related to ext from the tomcat-6.0.29\webapps\ROOT\WEB-INF\lib except ext-redeploy-6.0.5.jar
7) Start the Server
8) Deploy the EXT Portlet
9) After that it will ask for rebooting the server once the EXT portlet is successfully deployed.
10) Now once again start the server.

Your EXT portlet will re-deployed successfully and all the changes will get Executed.

Hope it helps !!!

Dynamic Query in Liferay

$
0
0
Liferay provides several ways by which we can retrieve data from database. One of them is dynamic query. You can easily fire complex query using dynamic query and it will reduce overhead of creating custom finder methods. Lets go step by step with easy example. If you want to fire simple AND query then here is the example.
DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(MyCustomTable.class);
dynamicQuery.add(PropertyFactoryUtil.forName("status").eq("Pending")
dynamicQuery.add(PropertyFactoryUtil.forName("userId").eq(10122);

Above query will search in table MycustomTable for records which has status as Pending and userId as 10122. If you want to sort your records in particular order that also you can do.
Order defaultOrder = OrderFactoryUtil.desc("modifiedDate");
Order secondOrder = OrderFactoryUtil.desc("requestId");
dynamicQuery.addOrder(defaultOrder);
dynamicQuery.addOrder(secondOrder);

Above query will order records based on Modified Date and RequestId. Now if you want to fire some complex query like combination of or , And , Between and Like then here is the example. By using RestrictionFactoryUtil we can file OR , AND , Like and Between query.
DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(MyCustomTable.class);

Criterion criterion = null;

criterion = RestrictionsFactoryUtil.like("subject", StringPool.PERCENT + "Test Subject"+ StringPool.PERCENT);

criterion = RestrictionsFactoryUtil.and(criterion, RestrictionsFactoryUtil.between("create_date",10/02/2012,10/03/2012));

criterion = RestrictionsFactoryUtil.or(criterion , RestrictionsFactoryUtil.eq("status", "Pending"));

dynamicQuery.add(criterion); 

As you can see above query will try to fetch those records which has subject like "Test Subject" and its created_date is in between the above dates or the records which has status as pending. To execute dynamic query.

List requestList = MyCustomTableLocalServiceUtil.dynamicQuery(dynamicQuery);

Integrating Solr with Liferay 6

$
0
0
Building Solr & Installing Solr instance on tomcat.
  1. Download Solr-1.3.0 release from Solr.
  2. Unzip .tar on some location. For eg. /opt/solr/
  3. Make /opt/solr/example/solr as a $SOLR_HOME.
  4. Copy apache-solr-1.3.0.war file from /opt/solr/dist and paste it into /opt/solr/example/solr.
  5. Open up the /opt/solr/example/solr/conf/solrconfig.xml
    Replace
    <dataDir>${solr.data.dir: ./solr/data}</dataDir>
    by following 
    <dataDir>${solr.data.dir:/opt/solr/example/solr/data}</dataDir>
    Note:The dataDir can also be temporarily overridden with the JAVA_OPTS environment variable  prior to starting Tomcat
             export JAVA_OPTS="$JAVA_OPTS -Dsolr.data.dir=/opt/solr/example/solr/data"
  1. It is recommended to run the Solr instance on separate tomcat instance other than liferay tomcat.
  2. So for separate tomcat for solr, consider it here. $SOLR_TOMCAT
  3. Into $SOLR_TOMCAT/conf/Catalina/localhost , create one solr.xml file and copy following content into the file and save it.






  1. Now start tomcat and check that it is running without any error or not.
Integrating Solr plugin with Liferay

  1. Download Solr plugin which is compatible with the Liferay version.
  2. Drop the plugin into $LIFERAY_HOME/deploy directory.
  3. Start liferay tomcat server. After started liferay tomcat, just stop both the tomcat servers (SOLR_TOMCAT and LIFERAY_TOMCAT).
  4. Openup the $LIFERAY_HOME/tomcat-6.0.18/webapps/solr-web/WEB-INF/classes/META-INF/solr-spring.xml
           for bean id=”solrServer” give the solar tomcat settings and save it.
           for eg. http://localhost:8181/solr
  1. Copy the $LIFERAY_HOME/tomcat-6.0.18/webapps/solr-web/WEB-INF/conf/schema.xml file and paste it into /opt/solr/example/solr/conf/ directory.


Congratulation, you have done!

Tabs with Search Container in Liferay

$
0
0
Generally we have to write a lot of javascript and java code in order to deal with paging in Web based application.

But with liferay you don't have to deal with that any more. Your life become easier with liferay.

As I used to post regularly in liferay forums. I found that most of the people face issues of pagination with Tabbing.
Here I would represent how search container works with Tabs.

Below are some of the screenshot for the demo that I am going to discuss in this post.







As you will refer above screenshot, you will be able to see two tabs and both of them having list of data.
First Tab show the list of all the User Group and the Second Tab shows the list of all Users for the Current Company.

Below are the steps you need to follow :-

1) First Create the Controller Class which will extend the MVC Controller and put it's Entry in the portlet.xml.

com.blog.demo.controller.SearContainerController

2) In order to create the Tabbing View, you have to write below code in your jsp page. So in my case I have created the view.jsp and whose entry by default set in the portlet.xml.














<%@include file="/html/portlet/searchcontainer-with-tabs/tabs/usergroup.jsp" %>






<%@include file="/html/portlet/searchcontainer-with-tabs/tabs/user.jsp" %>







usergroup.jsp














user.jsp















NOTE :- Here on the basis of  "tabs" parameter, it will return the search container.

4) In order to make the code more readable, I created the seperate class for both the UserGroup i.e., UserGroupUtil and for User i.e.,UserUtil

UserGroupUtil
public class UserGroupUtil
{

    public static void searchContainerData(RenderRequest renderRequest,RenderResponse renderResponse)
    {
        List<usergroup> userGroupList = new ArrayList<usergroup>();
        Map<string tring="tring"> paramMap= new HashMap<string tring="tring">();

        paramMap.put("tabs", "UserGroup");

        PortletURL iteratorURL= renderResponse.createRenderURL();
        Iterator<map .entry=".entry" string="string" tring="tring">&gt; entries = paramMap.entrySet().iterator();
        while (entries.hasNext()) {
            Map.Entry<string string="string"> entry = entries.next();
            // System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
            iteratorURL.setParameter(entry.getKey(), entry.getValue());
        }
        PortletConfig portletConfig = (PortletConfig)renderRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);
        ThemeDisplay themeDisplay = (ThemeDisplay)renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
        SearchContainer<usergroup> searchContainer = new SearchContainer<usergroup>(renderRequest, null,
                null, SearchContainer.DEFAULT_CUR_PARAM, ParamUtil.getInteger(renderRequest,  SearchContainer.DEFAULT_DELTA_PARAM, 5),
                iteratorURL, null, LanguageUtil.get(portletConfig, themeDisplay.getLocale(), "No UserGroups were Found"));
        int total = 0;
        try {

            userGroupList=UserGroupLocalServiceUtil.getUserGroups(themeDisplay.getCompanyId());
            total = userGroupList.size();

        } catch (SystemException e) {
            SessionErrors.add(renderRequest, SystemException.class.getName());
        }
        userGroupList = ListUtil.subList(userGroupList, searchContainer.getStart(), searchContainer.getEnd());

        searchContainer.setTotal(total);
        searchContainer.setResults(userGroupList);
        renderRequest.setAttribute("userGroupSearchContainer", searchContainer);

    }
}


UserUtil

public class UserUtil
{

    public static void searchContainerData(RenderRequest renderRequest,RenderResponse renderResponse)
    {
        List<user> userList = new ArrayList<user>();
        Map<string tring="tring"> paramMap= new HashMap<string tring="tring">();

        paramMap.put("tabs", "User");

        PortletURL iteratorURL= renderResponse.createRenderURL();
        Iterator<map .entry=".entry" string="string" tring="tring">&gt; entries = paramMap.entrySet().iterator();
        while (entries.hasNext()) {
            Map.Entry<string string="string"> entry = entries.next();
            // System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
            iteratorURL.setParameter(entry.getKey(), entry.getValue());
        }

        PortletConfig portletConfig = (PortletConfig)renderRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);
        ThemeDisplay themeDisplay = (ThemeDisplay)renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
        SearchContainer<user> searchContainer = new SearchContainer<user>(renderRequest, null,
                null, SearchContainer.DEFAULT_CUR_PARAM, ParamUtil.getInteger(renderRequest,  SearchContainer.DEFAULT_DELTA_PARAM, 10),
                iteratorURL, null, LanguageUtil.get(portletConfig, themeDisplay.getLocale(), "No Users were Found"));
        int total = 0;
        try {

            userList = UserLocalServiceUtil.getCompanyUsers(themeDisplay.getCompanyId(), -1, -1);
            total = userList.size();

        } catch (SystemException e) {
            SessionErrors.add(renderRequest, SystemException.class.getName());
        }
        userList = ListUtil.subList(userList, searchContainer.getStart(), searchContainer.getEnd());

        searchContainer.setTotal(total);
        searchContainer.setResults(userList);
        renderRequest.setAttribute("userSearchContainer", searchContainer);

    }
}

In order to work pagging in proper way for search container with different tabs. We need to create the iterator URL in proper manner. Because Pagging in Search Container works based on IteratorURL. So we need to pass proper parameter in the Iterator URL. The Below code plays an key role in the Tabbing with Search Container.
Map<String,String> paramMap= new HashMap<String,String>();



        paramMap.put("tabs", "User");



        PortletURL iteratorURL= renderResponse.createRenderURL();

        Iterator<Map.Entry<String, String>> entries = paramMap.entrySet().iterator();

        while (entries.hasNext()) {

            Map.Entry<String, String> entry = entries.next();

            // System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());

            iteratorURL.setParameter(entry.getKey(), entry.getValue());

        }

In the above code I used HashMap, because if we have more parameter to pass then we can pass easily in the Iterator URL. Hope it will be useful !!!!

Mobile Theme in Liferay

$
0
0
Now no need to do any nightmare work for creating mobile theme. No need to find User Agents and writting different CSS for different device. Single CSS will work for all device.

You are just few steps away for becoming expert in Mobile Theme.

NOTE :- Considering that you are aware of creating the Basic Theme in Liferay.

1) Create a Simple theme as we are creating for normal website portal(Make CSS code as percentage specific rather than Pixel specific for width Especially.).

2) While creating theme, Don't forget to add two most important things.
  •      In the portal_normal.vm, header section put the below line
    <meta name="viewport" content="target-densitydpi=160dpi, width=device-width, minimum-scale=1, maximum-scale=1">
  •      In the Script part add below line
     AUI().use('aui-viewport');

Above Two lines will handle your theme according to your device.

3) Complete your coding part that you required for creating the theme( Navigation , footer, etc).

4) Once the Development part is done from your end then you need to do the Configuration part for different device.  

5) Now no need to find user-Agent in Liferay with if and else conditions on the Code of theme. Liferay has solved that problem for us now. Liferay has introduced Mobile Device Rules which will do our work.

6) In order to make it compatible with different Devices like Iphone,Ipad,Android Devices you need to install plugins called WURFL.

 http://sourceforge.net/projects/lportal/files/Liferay%20Plugins/6.1.0%20GA1/wurfl-web-6.1.0.1-ce-ga1-20120106155615760.war/download

7)
Once You installed Plugins. Follow the below Video to create different rules for different devices.



8)
If you don't have device with you for testing then Install User-Agent Switcher in browser for Chrome and also for Firefox ( Required to restart the browser once you switch the User-Agent).

Thank You Guys for reading. Please post your comments and reviews.

New Features in Liferay Portal v6.2

$
0
0
With every new version of Liferay, it is becoming more robust and easy to use. As I am the member of Liferay 6.2 Comunnity Verifier Group, So I am quite excited to explore its features.

Here I am going to list down some of the new features that you are going to see in Liferay 6.2 CE.

UI Refinements


In the Liferay 6.2 CE Version you will see all the things are very much organized or Categorize form then the previous version.
  • Look & Feel :- When I downloaded the latest tomcat bundle of liferay 6.2 CE, the first thing I noticed is there is a change in the Default Liferay theme. Liferay is now upgraded to Alloy 2.0.

Liferay 6.1 Theme
Liferay 6.2 Theme

  •   Dockbar :- The Second thing that come into focus is the Dockbar. In Liferay 6.2 they have made it more Categorize form. They have Categorize Admin(Control Panel) and MySites which all comes together in GOTO Section in liferay 6.1 version.

Liferay 6.1 Dockbar
Liferay 6.2 Dockbar
      
    • Control Panel :- There was a Major Change in the Control Panel Section. It was divided into Four Sections
        • Users - It contains User, UserGroup, Password Policies, Roles, Organization etc in this section.
        • Sites - It contains Sites,Sites Template,Page Template,Blogs,Wiki, Document and Media etc in this section.
        • Apps - It contains Market Place,Plugins Configuration, Plugins Installation etc in this section.
        • Configuration - It contains Portal Settings,Custom Fields,Server Administration and Portal Instances in this section.                   

      Control Panel
                          Liferay 6.1 Control Panel                                                         Liferay 6.2 Control Panel

      Sites


      There are couple of changes and also new portlets are added at site level.
      • Recycle Bin :- The name itself speaks a lot. You all knows what the Recycle Bin do in Windows or Trash in Mac. The same feature liferay has implemented here.

        In Previous versions of liferay if a user accidentally deletes a document from the Documents and Media portlet, the user has no way to easily restore the document.After this feature is implemented, as an end user, you can easily restore your deleted files by going to the recycle bin to restore files that have been deleted lately. It also provides automatically clean up the Recycle Bin if the file entry is older than one month.    
                                                    
      Liferay 6.2 Recycle Bin Portlet

      • Web Content Management :- You can now organize Web Content in Folders and Sub-Folders in the same way as Document and Media.

       

      Liferay 6.2 WCM

      • New Template Script Editor with Auto complete :- Good to have this. It was hectic to write scripts in previous versions. It will make life easier.

      Liferay 6.2 Script Editor

      • Application Display Templates :-  We can make our own Custom templates for Wiki, Blogs, Asset Publisher etc.


      Liferay 6.2 Application Display Templates


      And lots More .......


      Create WebContent and Integrate Flow Player to Play Videos in Liferay

      $
      0
      0
      Most of the times we have a requirement from the client to show videos on the home page for marketing purpose or to promote the brands. At that time I looked into the internet for so many different players but I found the Flow Player as the Most efficient and easy to integrate it.

      Note:- Download source code at the end of this blog.

      Below are some of the Features of Flow Player which make him so much popular:-
      • Basic Features
        •   Play/Pause Controls
        •   FullScreen
        •   Playlist 
      • Advance Features
        •  Common Clipping ( for eg. :-  you can set the duration for all the files in the playlist to play for only 5 seconds )
        •  Clipping ( for eg. :-  you can set the duration for each and every individual file in the playlist)
        •  Advertising ( You can integrate Advertising in the Flowplayer same as you see in the youtube )
        •  Streaming ( Online streaming from live server )
      There are so many different video formats are available on Internet. Some Particular format of Video required respective company's Player but some other formats are open and other players can play them.

      As FlowPlayer runs on Flash Video Object, so it can virtually handle all format which are supported by flash.

      Supported Video Format

      Here I am going to show you the small demo about how to integrate Flow Player in Liferay and play videos with the help of it.

      List of the necessary files required in order to integrate Flow Player with Liferay are as below:-

      jquery1.8.js - Javascript file required for the Flow Player.
      flowplayer-3.2.12.min.js - Javascript file required for the Flow Player.
      flowplayer.ipad-3.2.12.min.js - Optional Javascript file required for the Flow Player to make Ipad Compatible.
      flowplayer-3.2.16.swf - Flash File required in order to play Video or Audio.
      flowplayer.controls-3.2.15.swf - Flash File which contains Controls of Flow Player like Volume Control, Slider, Play/Pause etc.

      We can integrate the Flow player in two ways either we can use Web Content(Structure/template) or directly integrate in the Liferay Portlet.

      Here we are going to see Flow Player integration with Web Content(Structure / Template)

      There are three ways to include the Javascript and Flash file :-

      1) If you have developed a theme for your site then put the Javascript and Flash files in theme and then include in Velocity(Template).

      1. Folder Structure in theme

      2) Put the JavaScript and Flash Files in the Document and Media.

      2. Files in Document and Media

      3) Most appropriate way, put the Javascript files in the Theme and Flash Files in Document and Media.

      3.1 Files and Folder in Theme
      3.2 Files in Document and Media





      Here we are using the third approach.

      After configuring the files, now we will start with creating the web-content.

      Web Content is Divided in three Parts as below :-

      1) Creating Structure.  2) Creating Template. 3) Creating Content.

      4. Liferay 6.1 Web Content

      1) Creating Structure


      4.1 Creating Structure
      After Clicking on the Add Structure button the below screen appears.

      4.1.1 Structure GUI

      Name and Description are the fields in order to name the Structure and also give appropriate description for that structure.

      After Scrolling Down you will find XML Schema Definition section. Click on the Add Row button and go on adding as per below screenshot.

      4.1.2 Structure XML Schema GUI
      We have added three fields in XML Schema as per above screenshot.

      VideoFile - Type as Text-Field (It will contain the path of the Video like Flv or mp4 file path).
      SWFPlayer - Type as Document and Media ( It will have the flowplayer-3.2.16.swf file from the Document and Media).
      SWFPlayerControl - Type as Document and Media ( It will have the flowplayer.controls-3.2.15.swf file from the Document and Media).

      Now we are done with our Structure part.

      2) Creating Template

      4.2 Lifeay 6.2 Creating Template
      After clicking on the Add Template button the below screen appears.

      4.2.1 Template GUI
      Name and Description are the fields in order to name the Template and also give appropriate description for that Template.
      Cacheable is for caching the content.
      Structure Selection is for selecting the structure that we have created
      Language Type is for writting the Template code in different languages (VM,CSS,FTL,XSL)
      Launch Editor will open the Screen in which you will be able to write the Template Code.

      As you see in screenshot, the Editor with Default Code. Remove that Default Code and add below code in your editor.

      Click on update button of Editor and now Save the Template.

      Explanation of Template Code
      • $image-path will find the image path from theme.
      • 2nd and 3rd line is for importing the javascript file that we need to include in Flow Player. But one important thing is that as our Javascript File is in the JS Folder so we moved upto JavaScript Path from ImagePath accordingly.
      • Now we have defined link with id as player and href is the location where we will get video file path from the Web-Content Dynamically.
      • As we have written Flow Player configuration in ready function of the JavaScript. So When the page will be loaded and it will be ready then Javascript ready function will get called. In that our Flow Player function will be called.
      • First parameter in the flow player function is the id of the anchor where we want to place the flow player.
      • Second parameter in the flow player function is the parameter that contains the Main SWF File Path.
      • Third Parameter is the Plugins of the Flow Player. Here we used Play/Pause, Slider that contains inside the Plugins swf.
      • We can add more parameter if we want in the Flow Player functions.
      3) Creating Web-Content

      4.3 Create Web Content

      There are two option either Basic Web Content or Flow Player :-

      If you select Basic Web Content then you have to manually select Structure and Template for that web content.
      But if you select FlowPlayer then it will automatically select Structure and Template of Flow Player.

      After Clicking on it below screen appears.

      4.3.1 GUI of Web Content

      Title -  Will be appropriate title for the Web Content
      Video file - It is the parameter that we defined in the Structure. Add the appropriate path of the Video File
      SWF Player& SWF Control File that we need to select it from the Document and Media as we have specified in Structure.

      After selecting the SWFPlayer and SWFPlayer Control appropriate SWF's. Click on the Publish Button.

      Your Web Content is Created.

      Now go any page in the site with Site Administrator or Administrator as a Role in liferay.
      You will see the ADD Button on the DockBar.
      Click on the ADD Button and select Web Content Display Portlet. It will appear in the page.
      From the Web Content Display Portlet select Flow Player. It will appear as below :-

      Flow Player integrated with Web Content


      Congrats !! Now your job is done.

      Download complete source code from here.

      Hope it will be useful.
      Viewing all 12 articles
      Browse latest View live