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!

Donnerstag, 17. April 2008

Equinox in a Servlet Container Step by Step

If you want to run OSGi with Servlets on an Apache Tomcat for example a very good start is Equinox in a Servlet Container
First do the things with the number 1,2 and 3 you can find in the section Quickstart.
And now it is time to install and get to run the sample.http and sample.http.registry examples.
Download these both examples and extract them anywhere on your harddisk.
Now start Eclipse and choose File>Import>General>Existing Projects into Workspace and import these both projects.Then these both projects can be seen in your eclipse project explorer. Now export them both as jar on your harddisk and please not in a directory of your tomcat. Make a rightklick on the sample.http project and choose export>jar.

In the next step choose a place where the jar should be exported. It is not in your tomcat directory but anywhere on your harddisk:

In the next window click on next and be careful with the next window:

Here you have to choose the manifest file of the sample.http project. Click then on finish and do these same steps with the sample.http.registry.
At the end you should have two jars.

Tomcat should run now, so please start it if it not does.
You should see the console now:

Now write in this window -console and hit the Enter-button to get the osgi console. The result should be that:

Now you have to install these two jars you exported before. Enter in the console
install file:/pathofthejar/jarname for the samplehttp.jar and the samplehttpregistry.jar.
In my case it is this:

The result are two ids for every jar.
Now start this jars with start id. In my case it is start 14 and start 15 as you see here:

Now with the command ss you can see the status and these both plugin should run and have the status ACTIVE.

Now your plugins are running and correctly installed.
You can see them in action if you type hostOfTomcat/directory where bridge is installed/helloworld for sample.http and hostOfTomcat/directory where bridge is installed/ext/helloworld for sample.http.registry.
In my case http://localhost:8080/bridge/helloworld and http://localhost:8080/bridge/ext/helloworld
Have fun!