Friday, August 6, 2010

Inter Portlet Communication (IPC) for Portlets on Different Page

Use the below code for Inter Portlet Communication (IPC) for Portlets on Different Page:-

String plidName = "Sample_WAR_Sampleportlet";
long plidForward = getPortletId(plidName);
PortletURL url = new PortletURLImpl(request,plidName, plidForward, PortletRequest.ACTION_PHASE);

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

public static long getPortletId(String portletId) {

PortletPreferences prfs = null;
try {
DetachedCriteria dCriteria = DetachedCriteria
.forClass(PortletPreferences.class);
dCriteria.add(Restrictions.eq("portletId", portletId));
DynamicQuery dynamicQuery = new DynamicQueryImpl(dCriteria);

List list = PortletPreferencesLocalServiceUtil.dynamicQuery(dynamicQuery);

if (!list.isEmpty()) {
prfs = (PortletPreferences) list.get(0);
}

} catch (Exception e) {
e.printStackTrace();
}
return prfs.getPlid();
}

Friday, July 30, 2010

Liferay Service Builder

Liferay has very good service builder
utility. We can specify our domain model in
a service.xml file and run an ant task. The
utility will create Java files, Hibernate files,
Service Builder
and service classes

• Service Builder is a RAD tool, we may
choose to use our own service framework
and layer instead

Liferay supports Web Services

Liferay supports Web Services :-

• JSON
• Hessian
• Burlap
• REST
• RMI
• Spring HTTP
• WSRP
• WebDAV

Thursday, July 29, 2010

HashMap sort by key

HashMap map = new HashMap();

map.put("05", "500");
map.put("04", "400");
map.put("03", "600");
map.put("01", "100");

Object[] key = map.keySet().toArray();
Arrays.sort(key);

for (int i = 0; i < key.length; i++) {
System.out.println(map.get(key[i]));
}

Thursday, March 11, 2010

Inter Portlet Communictaion For Session Attributes

If we set any value in session it will be available until session available.

Include Following Line in liferay-portlet.xml:
<private-session-attributes>false</private-session-attributes>

Create session attribute in any file:
PortletSession ps = req.getPortletSession();
ps.setAttribute(key, value, PortletSession.APPLICATION_SCOPE);

Example:
ps.setAttribute("SAMPLE_ATTRIBUTE", "sample", PortletSession.APPLICATION_SCOPE);

Access in other Portlet File:
String name = ps.getAttribute("SAMPLE_ATTRIBUTE", PortletSession.APPLICATION_SCOPE);
Now name contains sample.

Programmatically import LAR file into Liferay.

public static void addDefaultLayoutsByLAR(
long userId, long groupId, boolean privateLayout, File larFile)
throws PortalException, SystemException {

Map parameterMap = new HashMap();

parameterMap.put(
PortletDataHandlerKeys.PERMISSIONS,
new String[] {Boolean.TRUE.toString()});
parameterMap.put(
PortletDataHandlerKeys.PORTLET_DATA,
new String[] {Boolean.TRUE.toString()});
parameterMap.put(
PortletDataHandlerKeys.PORTLET_DATA_CONTROL_DEFAULT,
new String[] {Boolean.TRUE.toString()});
parameterMap.put(
PortletDataHandlerKeys.PORTLET_SETUP,
new String[] {Boolean.TRUE.toString()});
parameterMap.put(
PortletDataHandlerKeys.USER_PERMISSIONS,
new String[] {Boolean.FALSE.toString()});

LayoutLocalServiceUtil.importLayouts(
userId, groupId, privateLayout, parameterMap, larFile);
}

Installing Liferay 5.2.3 on Existing Apache Tomcat 6.0.24

1. Download and install Apache Tomcat 6.0.24 into your preferred directory.

2. Download and install JDK 5 . Set an environment variable called %JAVA_HOME% (in Windows) or $JAVA_HOME (in Linux/UNIX) to point to your JDK directory.


3. Create and edit $TOMCAT_HOME/conf/Catalina/localhost/ROOT.xml to set up the portal web application.
<Context path="" debug="0" reloadable="true" cookies="true" crossContext="false" privileged="false" />


4. Download liferay-portal-5.2.3.war.


5. Download Liferay's Portal 5.2.3 Dependencies.

5.1. Create a $TOMCAT_HOME/lib/ext directory and unzip the dependencies ZIP in there.

6. Edit $TOMCAT_HOME/conf/catalina.properties. common.loader= ${catalina.home}/common/classes,\ ...\ ${catalina.home}/common/lib/ext/*.jar


7. Make sure your database server is installed and is working.
If it's installed in a different machine make sure that it's accessible from the one where Liferay is being installed.


8. Configure data sources for your database. Make sure the JDBC driver for your database is accessible by Tomcat.
8.1. Obtain the JDBC driver for your version of the database server. In the case of MySQL use mysql-connector-java-{$version}-bin.jar.
8.2. Copy the JAR file to $TOMCAT_HOME/lib/ext

9. Create a database for Liferay.
For example: create database lportal character set utf8; Liferay will automatically create the tables and populate it the first time it starts.

10. To add support for accessing Liferay's services remotely and to access the document library using WebDAV follow these steps:
10.1. Download tunnel-web.war
10.2. Create a directory called $TOMCAT_HOME/webapps/tunnel and unzip the WAR contents inside

11. Create $TOMCAT_HOME/conf/jaas.config.

PortalRealm { com.liferay.portal.kernel.security.jaas.PortalLoginModule required; };


12. Edit $TOMCAT_HOME/bin/catalina.bat so that Tomcat can reference the login module.
set JAVA_OPTS=-Xms128m -Xmx512m -Dfile.encoding=UTF8 -Duser.timezone=GMT -Djava.security.auth.login.config=%CATALINA_HOME%/conf/jaas.config

13. Delete contents $TOMCAT_HOME/webapps/ROOT directory.


14. Unpack liferay-portal-5.2.3.war to $TOMCAT_HOME/webapps/ROOT.


15. For supporting UTF-8 UIRIEncoding, edit $TOMCAT_HOME/conf/server.xml.


16. Run Tomcat, point browser to http://localhost:8080. Sign in as test@liferay.com and password test


NOTE: ---- ************copy the following jar files in lib/ext folder to avoid startup problem:********
activation.jar annotations.jar ccpp.jar container.jar hsql.jar jms.jar jta.jar jutf7.jar mail.jar mysql.jar portal-kernel.jar
portal-service.jar portlet-container.jar portlet.jar postgresql.jar serializer.jar support-tomcat.jar xalan.jar xercesImpl.jar

xml-apis.jar