Montag, 27. Juli 2009

How to access ThemeDisplay from a bean in liferay?



public ThemeDisplay getThemeDisplay(){
FacesContext context = FacesContext.getCurrentInstance();
PortletRequest portletRequest = (PortletRequest)context.getExternalContext().getRequest();
ThemeDisplay themeDisplay = (ThemeDisplay)portletRequest.getAttribute(WebKeys.THEME_DISPLAY);
return themeDisplay;
}

Samstag, 25. Juli 2009

Redirect users in liferay to their private page

Imagine you want that a user after logging in the liferay portal is redirected to his private area. How you can achieve that?

Very easy:

Just add the entry

auth.forward.by.last.path=false

to the portal-ext.properties file

You don't know where the portal-ext.properties file is?


Here:

[liferay-portal]/[servletcontainer]/webapps/ROOT/WEB-INF/classes

If this file does not exist create it please.


Ready!

How to get running the icefaces portlet samples with liferay?

The icefaces distribution includes many samples and the both portlet samples location and chat. You need to have installed ant to be able to build them.
You can find these examples in [ICEFaces-xxx-bin]/icefaces/samples/portlet.
To use them in liferay - I tested it with the version 5.2.2 - you need to change a small thing in both of them.
For the location-portlet you need to add in location/conf/web.sunri.icefaces.xml
the following entry

<context-param>
<param-name>com.icesoft.faces.compressResources</param-name>
<param-value>false</param-value>
</context-param>

And then you can build this portlet with ant and it should run in liferay.

For the chat-portlet you have to change the entry in chat/conf/web.sunri.icefaces.xml
from

<context-param>
<param-name>com.icesoft.faces.compressResources</param-name>
<param-value>true</param-value>
</context-param>

to

<context-param>
<param-name>com.icesoft.faces.compressResources</param-name>
<param-value>false</param-value>
</context-param>

Then build it with ant.

Have fun ;-)

Samstag, 11. Juli 2009

How to access portal-impl.jar and another liferay jars?

The Liferay distribution includes many jars that you want perhaps use in your own application. For example you may want to add new users to liferay from your own portlet and then this portlet have to use portal-impl.jar.
I use Liferay with tomcat and the specific jar can be found in TOMCAT_ROOT/webapps/ROOT/WEB-INF/lib.
So you need to take this jar to compile your portlet. But you are not allowed to add this to your war, because it is not allowed that the same jar - in this case portal-impl.jar - is in your war and in TOMCAT_ROOT/webapps/ROOT/WEB-INF/lib.
But how can your application access these jars?
You have to add to your WEB-INF folder the file
liferay-plugin-package.properties.
There you specify the jars that your application should use out of the TOMCAT_ROOT/webapps/ROOT/WEB-INF/lib folder.
In the key portal-dependency-jars you define the jars should be used.

Example:

name=NeededJarsTest
module-group-id=liferay
module-incremental-version=1
tags=sample
short-description=Demonstration how to access jars
change-log=
page-url=http://g-itblog.blogspot.com
author=Gastons-IT-Blog
licenses=LGPL

portal-dependency-jars=\
commons-beanutils.jar,\
commons-collections.jar,\
commons-digester.jar,\
commons-fileupload.jar,\
commons-lang.jar,\
commons-validator.jar,\
oro.jar,\
portal-impl.jar

speed-filters-enabled=false

Samstag, 4. Juli 2009

Start notepad with java

Open notepad with java


private void execute() {
Runtime r=Runtime.getRuntime();
try {
Process p=r.exec("notepad.exe");
} catch (IOException e) {
e.printStackTrace();
}
}




Open a file in notepad with java


private void execute() {
Runtime r=Runtime.getRuntime();
try {
Process p=r.exec("notepad.exe C://yourfile.txt");
} catch (IOException e) {
e.printStackTrace();
}
}

Samstag, 27. Juni 2009

Liferay get all Roles

If you need to get all roles from your liferay portal you can achieve it in this way:



public void listAllRoles()
{
try {
List companies=CompanyLocalServiceUtil.getCompanies();
for(Company company:companies)
{
List roles=RoleLocalServiceUtil.getRoles(company.getCompanyId());
for(Role role:roles)
{
System.out.println(role.getRoleId()+" "+role.getName());
}
}
} catch (SystemException e) {
e.printStackTrace();
}
}

Dienstag, 15. Juli 2008

Spring Dynamic Modules

The Equinox servlet bridge is a nice thing. If you only need JSP / JSTL it's a super base to build your OSGi-Webapplication. The problem is there are not yet JSF Plugins to get running JSF.
So there are some ways to achieve this. One of them is to use Spring Dynamic Modules. But the begin is never easy. But I was lucky and found a great tutorial on springosgi.googlepages.com. Because I had many questions in the Google Group Spring Osgi Oleg was so friendly and extended his tutorial on JSF. Great!