Showing posts with label liferay. Show all posts
Showing posts with label liferay. Show all posts

Wednesday, June 24, 2015

Liferay Connected Services

Liferay Connected Services



Liferay Connected Services is a new online platform that offers a set of tools and services that will help our customers succeed on their Liferay projects. read more https://www.liferay.com/products/liferay-connected-services

Monday, October 15, 2012

Disable "Request processed successfully" Message

1. Add this in portlet.xml

<init-param>
    <name>add-process-action-success-action < /name>
    <value>false
< /init-param>

2. If you want to change for a particular action rather than for all actions.

public void addBook(ActionRequest actionRequest,
                                  ActionResponse actionResponse)
                                throws IOException, PortletException {

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

    String successMsg = "Book added Successfully!";

    SessionMessages.add(actionRequest, "request_processed", successMsg);
}

Monday, January 31, 2011

Custom Sql in Liferay Plugin Portlet

Create a Custom Query in Plugin Portlet for Liferay Models(Liferay 6.0.x).

Step 1 :- Creating a library portlet
===========================

In the $PLUGINS_SDK/portlets(Windows)

create library-portlet "Library"

Step 2 :-

in portlet.xml

< portlet-class > com.liferay.util.bridges.mvc.MVCPortlet < /portlet-class >
replace with
< portlet-class > com.mpower.action.LibraryPortlet < /portlet-class >


Step 3 :-


Create service.xml under docroot/WEB-INF


< ?xml version="1.0" encoding="UTF-8"? >
<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 6.0.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_6_0_0.dtd" >
< service-builder package-path="com.mpower" >
< author > Arun Kumar < /author >
< namespace > library < /namespace >
< entity name="Book" local-service="true" remote-service="false" >
< column name="bookId" type="long" primary="true" / >
< column name="name" type="String" / >
< column name="author" type="String" / >
< order by="asc" >
< order-column name="name" case-sensitive="false" / >
< /order >
< /entity >
< /service-builder >



Step 4 :-

a. Create a folder custom-sql under src

b. Create a file default.xml under src/custom-sql

< ?xml version="1.0"? >
< custom-sql >
< sql file="custom-sql/book.xml" / >
< /custom-sql >

c. Create a file book.xml, under src/custom-sql

< ?xml version="1.0"? >
< custom-sql >
< sql id="findBooks" >
< ![CDATA[
SELECT
*
FROM
library_book
WHERE
(library_book.name like ?)
]] >
< /sql>
< /custom-sql >

Step 5 :-

Create the file "BookFinderImpl.java" under service/persistence

public class BookFinderImpl extends BasePersistenceImpl implements
BookFinder {

}


Do ant build-service to generate necessary files.



Step 6 :-

Now write the logic to access the custom sql


public List findBooks(String name) throws SystemException {
Session session = null;
try {
session = openSession();
String sql = CustomSQLUtil.get(FIND_BOOKS);
SQLQuery query = session.createSQLQuery(sql);
query.addEntity("Book", BookImpl.class);
QueryPos qPos = QueryPos.getInstance(query);
qPos.add(name);
return (List)query.list();
}catch (Exception e) {
}
return null;
}

public static String FIND_BOOKS = "findBooks";



*** Make the necessary imports.


import java.util.List;

import com.liferay.portal.kernel.dao.orm.QueryPos;
import com.liferay.portal.kernel.dao.orm.SQLQuery;
import com.liferay.portal.kernel.dao.orm.Session;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
import com.liferay.util.dao.orm.CustomSQLUtil;


Step 7 :-

Now write the method in BookLocalServiceImpl.java


public class BookLocalServiceImpl extends BookLocalServiceBaseImpl {

public List findBook(String name) throws PortalException,
SystemException, RemoteException {

return BookFinderUtil.findBooks("%" + name + "%");
}


run ant build-service , this will update the corresponding api with new method defined.

Step 8 :-

a. Create init.jsp under docroot and add the below content


< %@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" % >
< %@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" % >
< portlet:defineObjects / >
< %@ page import="com.mpower.service.BookLocalServiceUtil" % >
< %@ page import="com.mpower.model.Book" % >
< %@ page import="java.util.*" % >

b. Create result.jsp under docroot/


< %@page import="com.liferay.portal.kernel.util.Validator"% >
< %@ include file="init.jsp" % >

<% List books = (List) request.getAttribute("result");
if(Validator.isNull(books))books = new ArrayList();

%>

< liferay-ui:search-container delta="10" emptyResultsMessage="no-books-were-found" >
< liferay-ui:search-container-results
results="< %= books % >"
total="< %= books.size( )% >"
/>

< liferay-ui:search-container-row className="com.mpower.model.Book" modelVar="book" >

< liferay-ui:search-container-column-text
name="Book Title"
property="name"
/ >

< liferay-ui:search-container-column-text
name="Author"
property="author"
/ >

< /liferay-ui:search-container-row >

< liferay-ui:search-iterator / >

< /liferay-ui:search-container >


C. Update the view.jsp

< %@ include file="init.jsp" % >
< portlet:actionURL var="findURL" name="findBooks" / >

< form action="< %= findURL.toString() % >" name="fm" method="post" >


< label > Book Title < /label > < input name="title" value=""/ > < input type="submit" value="Search"/ >

< /form >


d. Create the portlet class LibraryPortlet.java under src/com/mpower/action


package com.mpower.action;

import java.io.IOException;
import java.util.List;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletException;

import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.util.bridges.mvc.MVCPortlet;
import com.mpower.model.Book;
import com.mpower.service.BookLocalServiceUtil;

public class LibraryPortlet extends MVCPortlet{

public void findBooks(ActionRequest actionRequest,
ActionResponse actionResponse) throws IOException, PortletException {

String name = ParamUtil.getString(actionRequest, "title");

try {
List books = BookLocalServiceUtil.findBook(name);
actionRequest.setAttribute("result", books);
actionResponse.setRenderParameter("jspPage", "/result.jsp");
} catch (PortalException e) {
e.printStackTrace();
} catch (SystemException e) {
e.printStackTrace();
}


}
}




run "ant deploy" and check the search functionality in Library portlet.






Wednesday, January 12, 2011

Jasper Report with Liferay integration

JASPER REPORT
===============
1) step-1
~~~~~~~~~~~

package com.ext.portlet.<some>.service.impl;

public class <some>LocalServiceImpl extends <some>LocalServiceBaseImpl {

public void downloadReport() throws SystemException, PortalException{


UserLocalService service = UserLocalServiceUtil.getService();

DetachedCriteria dCriteria = DetachedCriteria.forClass(User.class);

dCriteria.add(Restrictions.eq("active", true));

DynamicQuery dynamicQuery = new DynamicQueryImpl(dCriteria);

List<user> userList = (List)service.dynamicQuery(dynamicQuery);
List<userandcontactinfo> userandContactInfoList = new ArrayList<userandcontactinfo>();
for(int i=0; i<userlist.size(); classloader="" contact);="" contact="" i++){="" user="" userandcontactinfo(user,="" userandcontactinfo="" userandcontactinfolist.add(userandcontactinfo);="" }="">LocalServiceImpl.class.getClassLoader();
JasperDesign jasperDesign;
JasperReport jasperReport;
JasperPrint jasperPrint;
try {

InputStream inputStream = classloader.getResourceAsStream("profiles.jrxml");

jasperDesign = JRXmlLoader.load(inputStream);


jasperReport = JasperCompileManager.compileReport(jasperDesign);
JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(
userandContactInfoList);
jasperPrint = JasperFillManager.fillReport(
jasperReport, null, ds);

String dest ;
File file = new File("");
dest = file.getAbsolutePath();

JasperExportManager.exportReportToPdfFile(jasperPrint, dest+"/profiles.pdf");

} catch (JRException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

------------------------------------------------------------------------------------

step-2
~~~~~~~~~~

package com.ext.portlet.<some>.action;

import java.io.Serializable;
import java.util.Date;

import com.ext.portlet.<some>.model.UserInfo;
import com.liferay.portal.model.Contact;
import com.liferay.portal.model.User;


public class UserandContactInfo implements Serializable {

/**
*
*/
private static final long serialVersionUID = 1L;
public UserandContactInfo(User user, Contact contact){

this.screenName = user.getScreenName();
this.firstName = user.getFirstName();
this.lastName = user.getLastName();
this.dob = user.getBirthday();
this.gender = (contact.getMale()?"Male":"Female");
this.emailAddress = user.getEmailAddress();
}


public String getEmailAddress() {
return emailAddress;
}
public String getFullName() {
return fullName;
}
public String getScreenName() {
return screenName;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}

private String emailAddress;
private String fullName;
private String screenName;
private String firstName;
private String lastName;


}

---------------------------------------------------------------------------------------------------------------------

step-3
~~~~~~~~~~~~


package com.ext.portlet.<some>.action;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.InputStream;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.ext.portlet.<some>.service.<some>LocalServiceUtil;
import com.liferay.portal.struts.PortletAction;
import com.liferay.portal.util.PortalUtil;
import com.liferay.util.servlet.ServletResponseUtil;

public class DownloadPdf extends PortletAction {

public ActionForward strutsExecute(
ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response)
throws Exception {

try {
<some>ServiceUtil.downloadReport();
InputStream is = new BufferedInputStream(
new FileInputStream("profiles.pdf"));

ServletResponseUtil.sendFile(response, "Profiles.pdf", is, "application/pdf");

return null;
}
catch (Exception e) {
PortalUtil.sendError(e, request, response);
return null;
}
}
}

--------------------------------------------------------------------------------------------------------------------

step-4
~~~~~~~~~~
jrxml file should be >>>>>>>>> ext-impl/src/profiles.jrxml
==============

<jasperreport bottommargin="20" columncount="1" columnspacing="0" columnwidth="535" issummarynewpage="false" istitlenewpage="false" leftmargin="30" name="profiles" orientation="Portrait" pageheight="842" pagewidth="595" printorder="Vertical" rightmargin="30" topmargin="20" whennodatatype="NoPages">
<property name="ireport.scriptlethandling" value="0">
<property name="ireport.encoding" value="UTF-8">
<import value="java.util.*">
<import value="net.sf.jasperreports.engine.*">
<import value="net.sf.jasperreports.engine.data.*">


<field class="java.lang.String" name="emailAddress">
<field class="java.lang.String" name="fullName">
<field class="java.lang.String" name="screenName">
<field class="java.lang.String" name="firstName">
<field class="java.lang.String" name="lastName">


<background>
<band height="0" issplitallowed="true">
</band>
</background>
< title > <br /> <band height="12" isSplitAllowed="true" ><br /> </band><br />
<pageheader>
<band height="19" issplitallowed="true">
<textfield evaluationtime="Now" hyperlinktarget="Self" hyperlinktype="None" isblankwhennull="false" isstretchwithoverflow="false">
<reportelement forecolor="red" height="18" key="textField" width="100" x="404" y="1">
<box></box>
<textelement>

</textelement>
<textfieldexpression class="java.lang.Integer"></textfieldexpression>
</reportelement>

</textfield>
</band>
<columnheader>
<band height="0" issplitallowed="true">
</band>
</columnheader>
<detail>
<band height="783" issplitallowed="true">
<textfield evaluationtime="Now" hyperlinktarget="Self" hyperlinktype="None" isblankwhennull="false" isstretchwithoverflow="false">
<reportelement height="18" key="textField" width="205" x="133" y="136">
<box></box>
<textelement>

</textelement>
<textfieldexpression class="java.lang.String"></textfieldexpression>
</reportelement>
<textfield evaluationtime="Now" hyperlinktarget="Self" hyperlinktype="None" isblankwhennull="false" isstretchwithoverflow="false">
<reportelement height="18" key="textField" width="271" x="133" y="37">
<box></box>
<textelement>

</textelement>
<textfieldexpression class="java.lang.String"></textfieldexpression></reportelement>
-------------
-----------
------------
---------
</textfield>
</textfield>
<columnfooter>
<band height="0" issplitallowed="true">
</band>
</columnfooter>
<pagefooter>
<band height="0" issplitallowed="true">
</band>
</pagefooter>
<lastpagefooter>
<band height="16" issplitallowed="true">
</band>
</lastpagefooter>
<summary>
<band height="15" issplitallowed="true">
</band>
</summary>
</band>

--------------------------------------------------------------------------------------------------------------------


step-5
~~~~~~~~~

Required jars


a) jasperreports-3.0.0.jar >>>>>>>>tomcat/webapps/ROOT/WEB-INF/lib
b) itext-1.3.1.jar >>>>>>> tomcat/webapps/ROOT/WEB-INF/lib

JasperReports 3.5 for Java Developers

Liferay Alloy Popup

In Liferay's previous versions, we are using Liferay.Popup for popup window using jQuery.

As Liferay is moved to Alloy UI , Here is the code for Alloy Popup:


To Display some Html content in Alloy Popup:


< aui:script >

function callPopup(){

AUI().ready('aui-dialog', 'aui-overlay-manager', 'dd-constrain', function(A) {

var dialog = new A.Dialog({

title: 'DISPLAY CONTENT',

centered: true,

modal: true,

width: 500,

height: 400,

bodyContent: "This is testing content inside the popup"

}).render();

});

}

</aui:script >




Passing URL : Passing URL into Alloy Popup

<aui:script>

Liferay.provide(window,'<portlet:namespace />callPopup',

function(url1) {

var A = AUI();

var data = {};

var dialog = new A.Dialog(

{

centered: true,

destroyOnClose: true,

modal: true,

title: Liferay.Language.get('Display-Content'),

width: 600

}

).render();

dialog.plug(

A.Plugin.IO,

{

data: data,

uri: url1

}

);

},

['aui-dialog', 'aui-io']

);

</aui:script >

Liferay in Action: The Official Guide to Liferay Portal Development

Wednesday, November 18, 2009

SignOut Message in .vm File

Step: 1
Add the below lines in LogoutAction.java
after session.invalidate();
HttpSession logoutSession = request.getSession();
logoutSession.setAttribute("logoutSession", logoutSession);


Step: 2

create EXTServicePreAction.java under (com.liferay.portal.events.EXTServicePreAction.java )


EXTServicePreAction.java

package com.liferay.portal.events;

import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.liferay.portal.kernel.events.Action;
import com.liferay.portal.kernel.events.ActionException;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.util.WebKeys;

public class EXTServicePreAction extends Action {


public void run(HttpServletRequest req, HttpServletResponse res)
throws ActionException {
Map vmVariables = new HashMap();
HttpSession session = req.getSession();
HttpSession logoutSession = null;
logoutSession = (HttpSession)session.getAttribute("logoutSession");

try {
if(Validator.isNotNull(logoutSession)){
logoutSession.setAttribute("flag", true);
}else{
logoutSession = req.getSession();
logoutSession.setAttribute("flag", false);
}
} catch (Exception ex) {
Logger.getLogger(EXTServicePreAction.class.getName()).log(Level.SEVERE, null, ex);
}
vmVariables.put("logoutSession", logoutSession);

req.setAttribute(WebKeys.VM_VARIABLES, vmVariables);
}
}

step: 3
Add the below line in portal-ext.properties

servlet.service.events.pre=com.liferay.portal.events.ServicePreAction,com.liferay.portal.events.EXTServicePreAction



step: 4

Add the below line in portal_normal.vm

#if ($logoutSession.getAttribute("flag"))
<div>
<b>Successfully Logout</b>
$logoutSession.invalidate()
</div>
#end

Monday, July 27, 2009

liferay-clustering

Running Liferay in a clustered environment consists of 6 steps.

1. Preparations and getting things ready.
2. Connecting to a remote MySQL database.
3. Running 2 or More "IDENTICAL" Liferay tomcat instances on 2 Or more physical machines.
4. Making one machine as "Apache Web Server"
5. Connecting apache with tomcat using apache module "mod_jk"
6. Configuring mod_jk for clustering for both load-balancing and fail-over.
7. Verifying whether clustering is working fine.

=================================================================================

1. Preparations and getting things ready.

Select 4 physical machines (servers) in your LAN network. Each should have an internal IP address.

Just ping between the 4 machines and confirm that the pinging is successful.

Make sure none of the machines have fire wall running.

1 machine we'll use as Database server (Either windows or Linux) on which MySQL is installed and running
2 machines will be made as clustered servers on which identical verions of liferay is up running.
1 machine will be the apache http server which will be exposed to the outside world. Let this be a windows machine.
In the later part of this exercise we'll see how to run apache on a Linux server.

Note down the IP address of IP addresses of all four machines.

Machine 1 (MySQL) - [IP Address 1]
Machine 2-a (Liferay 1) - [IP Address 2]
Machine 2-b (Liferay 2) - [IP Address 3]
Machine 3 (Apache server with mod_jk) [IP Address 4]

----------------------------------------------------------------------------------------------
2. Connecting to a remote MySQL database.
----------------------------------------------------------------------------------------------

On the machine where mysql is running, open mysql prompt by typing "mysql -u root -proot mysql" from the command window.

Run these following scripts. Before running dont forget to modify the [IP Address X].

create database lportal2 character set utf8;

-- Giving access to the first Liferay machine (2-a)
---------------------------------------------------

insert into db (
Host
,Db
,User
,Select_priv
,Insert_priv
,Update_priv
,Delete_priv
,Create_priv
,Drop_priv
,Grant_priv
,References_priv
,Index_priv
,Alter_priv
,Create_tmp_table_priv
,Lock_tables_priv
,Create_view_priv
,Show_view_priv
,Create_routine_priv
,Alter_routine_priv
,Execute_priv
)
values (
"[IP Address 2]"
,"lportal2"
,"root"
,"Y"
,"Y"
,"Y"
,"Y"
,"Y"
,"Y"
,"N"
,"Y"
,"Y"
,"Y"
,"Y"
,"Y"
,"Y"
,"Y"
,"Y"
,"N"
,"N"
);

GRANT ALL ON lportal2.* TO root@'[IP Address 2]' IDENTIFIED BY 'root';

-- Giving access to the second Liferay machine (2-b)
-- --------------------------------------------------

insert into db (
Host
,Db
,User
,Select_priv
,Insert_priv
,Update_priv
,Delete_priv
,Create_priv
,Drop_priv
,Grant_priv
,References_priv
,Index_priv
,Alter_priv
,Create_tmp_table_priv
,Lock_tables_priv
,Create_view_priv
,Show_view_priv
,Create_routine_priv
,Alter_routine_priv
,Execute_priv
)
values (
"[IP Address 3]"
,"lportal2"
,"root"
,"Y"
,"Y"
,"Y"
,"Y"
,"Y"
,"Y"
,"N"
,"Y"
,"Y"
,"Y"
,"Y"
,"Y"
,"Y"
,"Y"
,"Y"
,"N"
,"N"
);

GRANT ALL ON lportal2.* TO root@'[IP Address 3]' IDENTIFIED BY 'root';

Important:

Once you have run the above scripts, pls dont forget to restart your MySQL.

Verification:

Now open the command window in the 2 machines where liferay is running and enter the command,

mysql -h [IP Address 1] -u root -proot lportal2;

This should successully get entry to the mysql prompt.

Do the similar thing on the other machine where Liferay is running and confirm that is it also connecting to
the remote Mysql database server.

Monday, July 20, 2009

Websites Developed by Liferay


http://www.paninicomics.it/web/guest/home
http://www.connexion.sg/web/guest/home
http://www.axxonet.net/web/guest/home
http://www.myoffice24x7.com/web/guest/home
http://www.mathforamerica.org/home
http://www.myjv.com/web/public/home
http://www.b-informed.de/web/guest/yapta
http://www.toyotahitel.hu/finanszirozas
http://www.afromix.info/web/news/
http://www.k4k.hu/nyitolap
http://www.euroleasing.hu/index
http://www.unisalento.it/web/guest/home_page
http://www.mebtel.net/pub/guest/home
http://www.netbiscuits.com/home
http://www.betavine.net/bvportal/home.html
http://www.kokkolaweather.fi/web/guest/home
http://www.ruralpovertyportal.org/web/guest/home
http://www.casagrandeaz.gov/web/guest/home
http://www.orshalom.org/web/guest/home
http://www.ntk.hu/web/guest/home
http://www.jsonlive.com/web/guest/jsonhome
http://www.soapractice.com/web/guest/home
http://207.210.217.14/web/guest/home
http://www.cise09.org/web/guest/home
http://www.xml-intl.com/web/guest/home
http://www.youthpeer.org/web/guest/home
https://teaming.dss.state.la.us/web/guest/home
http://p-learnet.univ-lille1.fr/web/guest/home
http://nfig.hd.free.fr/web/guest/home
http://www.lingresource.com/web/guest/home
http://www.skillsconnect.gov.sg/web/guest/home
http://developer.tandberg.com/web/guest/home
http://pennstatehershey.org/web/guest/home
http://learninglab.etwinning.net/web/guest/home
http://apps.zanox.com/web/guest/home
http://www.idmunit.org/web/guest/home
http://www.amishitayal.com/web/guest/home
http://www.benetton.com/portal/web/guest/home
http://www.centurioncargo.com/web/guest/home
http://www.sidsa.com/web/guest/home
http://www.icareus.com/web/guest/home
http://www.mybizsites.com/web/guest/home
http://ac.utm.my/web/guest/main
http://www.techweb.com/web/guest/home
http://www.mypic32.com/web/guest/home
http://gmoss.jrc.it/web/guest/home
http://www.nimbleartists.com/web/guest/home
https://www.skywayperspectives.org/portal/web/guest/home
http://www.nimbleartists.com/web/guest/home
http://wi2bc8.bwl.uni-mannheim.de/web/guest/home
http://www.ignouforum.com/web/guest/home
http://www.newedgegroup.com/web/guest/home
http://www.geoportal.org/web/guest/home
http://suhakam.org.my/web/guest/home
http://www.etiagarwal.com/web/guest/home
http://www.bankrakyat.com.my/web/guest/home
http://www.in4ama.org/web/guest/home
http://www.vivektayal.com/web/guest/home
http://www.uengine.org/web/guest/home
http://www.mdks.gov.my/web/guest/home
http://www.apolytrosis.gr/web/guest/home
http://einstein.mangala-server.com/liferay/web/guest/home