2/23/2011

Adding messages in Liferay(liferay-ui:success, liferay:ui:error)

Liferay offers several ways to present Messages to users. So we don´t always need to use ICEFaces and ice:message.


Showing Info Messages


Go into your Portlet Class and add the following:

SessionMessages.add(actionRequest, "your-key");


This just adds a marker into the session, that the message that is connected to that key should be displayed. To connect a key to a message, add the following to your JSP:


<liferay-ui:success key="your-key" message="your-message" />


This will create something like the following:








Showing Error Messages


Errors work in two ways: Either you add an error by using the same approach with the messages:



SessionErrors.add(actionRequest, "your-key");

<liferay-ui:error key="your-key" message="your-message" />

Or you use Exceptions (e here is an instance of some Exception class):

SessionErrors.add(actionRequest, e.getClass().getName(), e);

<liferay-ui:error exception="<%=SomeException.class%>"
message="your-message" />



If you liked this tutorial it would be very nice, if you could click on some of the google ads you see on the right side. It helps me run this block and motivates me ;)

If you have any questions, feel free to leave a comment.


2/19/2011

A Step by Step Tutorial for an ICEfaces "Hello World" Portlet on Liferay

Preparation


So, here it is: The ultimate way to create your first ICEfaces Portlet. In the end you will have a first ICEfaces 1.82 Portlet that you can develop in eclipse and use in Liferay. We will use Eclipse 3.6 and Liferay 6.05 CE.


To develop portlets in Eclipse, we will use the Liferay IDE. All you need to know is here: : http://www.liferay.com/de/community/wiki/-/wiki/Main/Liferay+IDE .


Liferay IDE will only work if you have the Community Edition of Liferay and it needs a plugins-sdk:


http://sourceforge.net/projects/lportal/files/Liferay%20Portal/6.0.5/liferay-plugins-sdk-6.0.5.zip/download


Download it, and unzip it to a folder of your choice.


If you installed Liferay IDE then click on "New Liferay Portlet":






Give your first nice portlet a name and click on "Finish". Now you should have a deployable JSP - Portlet. If you do not want to use ICEfaces, then you´re finished here.




Adding ICEfaces to your JSP - Portlet




There already is a "HelloWorld" portlet available for ICEfaces, which we will use here to get the libs and the correct configuration. Download the following war file:


http://en.sourceforge.jp/projects/sfnet_lportal/downloads/Liferay%20Plugins/5.2.0/sample-icefaces-jsf-1.2-sun-facelets-portlet-5.2.0.1.war/


This is basically as we need. Now copy all libs from WEB-INF/lib to your WEB-INF/lib folder.


Change your portlet.xml to only include the following:



<?xml version="1.0"?>

<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd">
<portlet>
<portlet-name>HelloWorld</portlet-name>
<display-name>Hello World</display-name>
<portlet-class>com.icesoft.faces.webapp.http.portlet.MainPortlet</portlet-class>
<init-param>
<name>com.icesoft.faces.VIEW</name>
<value>/View.iface</value>
</init-param>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>edit</portlet-mode>
<portlet-mode>help</portlet-mode>
</supports>
<portlet-info>
<title>Hello World</title>
<short-title>Hello World</short-title>
<keywords>Hello World</keywords>
</portlet-info>
<security-role-ref>
<role-name>administrator</role-name>
</security-role-ref>
<security-role-ref>
<role-name>guest</role-name>
</security-role-ref>
<security-role-ref>
<role-name>power-user</role-name>
</security-role-ref>
<security-role-ref>
<role-name>user</role-name>
</security-role-ref>
</portlet>
</portlet-app>

Change your Web.xml to only include the following:


<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
<context-param>
<param-name>org.jboss.jbossfaces.WAR_BUNDLES_JSF_IMPL</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>com.sun.faces.verifyObjects</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>com.sun.faces.validateXml</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>com.icesoft.faces.compressResources</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>com.icesoft.faces.concurrentDOMViews</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>com.icesoft.faces.delegateNonIface</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>com.icesoft.faces.hiddenPortletAttributes</param-name>
<param-value>THEME_DISPLAY</param-value>
</context-param>
<context-param>
<param-name>com.icesoft.faces.synchronousUpdate</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>com.icesoft.faces.uploadDirectory</param-name>
<param-value>C:\Uploads</param-value>
</context-param>
<context-param>
<param-name>com.icesoft.faces.uploadDirectoryAbsolute</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>com.icesoft.faces.uploadMaxFileSize</param-name>
<param-value>1024</param-value>
</context-param>
<listener>
<listener-class>com.icesoft.faces.util.event.servlet.ContextEventRepeater</listener-class>
</listener>
<servlet>
<servlet-name>Blocking Servlet</servlet-name>
<servlet-class>com.icesoft.faces.webapp.xmlhttp.BlockingServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>File Upload Servlet</servlet-name>
<servlet-class>com.icesoft.faces.component.inputfile.FileUploadServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>Persistent Faces Servlet</servlet-name>
<servlet-class>com.icesoft.faces.webapp.xmlhttp.PersistentFacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Blocking Servlet</servlet-name>
<url-pattern>/block/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>File Upload Servlet</servlet-name>
<url-pattern>/uploadHtml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Persistent Faces Servlet</servlet-name>
<url-pattern>*.iface</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Persistent Faces Servlet</servlet-name>
<url-pattern>/xmlhttp/*</url-pattern>
</servlet-mapping>
<resource-ref>
<res-ref-name>mail/MailSession</res-ref-name>
<res-type>javax.mail.Session</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<security-constraint>
<web-resource-collection>
<web-resource-name>Page Sources</web-resource-name>
<url-pattern>*.jsp</url-pattern>
<url-pattern>*.jspx</url-pattern>
<url-pattern>*.xhtml</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>nobody</role-name>
</auth-constraint>
</security-constraint>
<security-role>
<role-name>nobody</role-name>
</security-role>
</web-app>

Last step: Your first XHTML file. Add the file View.xhtml to your WEB-APP folder. It should contain the following:


<f:view xmlns:f="http://java.sun.com/jsf/core" xmlns:ice="http://www.icesoft.com/icefaces/component" xmlns:liferay-faces="http://liferay.com/tld/faces">
<ice:portlet>
<ice:form styleClass="sample-icefaces-portlet">
<ice:outputText value="hello world"/>
</ice:form>
</ice:portlet>
</f:view>

That should be all: You now have an ICEfaces - enabled portlet. Use it as a blueprint for other ICEfaces portlets.



If you liked this tutorial it would be very nice, if you could click on some of the google ads you see on the right side. It helps me run this block and motivates me ;)

If you have any questions, feel free to leave a comment.

2/17/2011

Migrate ICEFaces 1.8 to 2.0: Webinar

I´ve just seen that ICEfaces is offering a webinar about how to migrate an existing 1.8 ICEfaces application to 2.0. If you are interested, you can register here: Register


If you like this it would be very nice, if you could click on some of the google ads you see on the right side. It helps me run this block and motivates me ;)

If you have any questions, feel free to leave a comment.

2/16/2011

about the portletfaces example of an ICEfaces 2.0 portlet

Just had a look at the sources of the ICEfaces 2.0 Portlet available at www.portletfaces.org, and ... they are not using any ICEfaces tags (except the singlesubmit) at all.


I added an ice:outputText and it wasn´t rendered ... hmmmmm ... strange, strange. I think, I will stick to ICEfaces 1.82 a little longer than I thought ...

2/15/2011

getElementByID and Liferay

If you ever used AlloyUIs aui:input or the equivalent Liferay Tag to render an input field, you will surely have noticed, that Liferay adds the portlet id to all ids of all elements on the page. This makes sure, that two portlets with the same ids can coexist on the same portlet page without interferring with each other.
But how do you address them in javascript ? 


Just use the following standard liferay tag:<portlet:namespace />


Example:



<aui:input name="name" type="text" id="someid"/>


This will render to :



<input class="aui-field-input aui-field-input-text"  id="_44_someid" name="_44_name"   type="text" value=""   />

To address this with javascript use the following snippet



ishcpElement = document.getElementById("<portlet:namespace />someid");



If you liked this tutorial it would be very nice, if you could click on some of the google ads you see on the right side. It helps me run this block and motivates me ;)

If you have any questions, feel free to leave a comment.

2/14/2011

Getting started with Liferay 6 and ICEfaces 2.0 - Part 1

Because of a request on linkedin (http://de.linkedin.com/in/liferayblogging) I am putting together a "Hello World" for Liferay 6 and ICEfaces 2.0. There are plenty of introductions, tutorials and "hello worlds" out there, so what I intend to do for Part 1 is to link to the best of them (mostly from the official pages). Part 2 will contain a step-by-step introduction on how to create an ICEfaces portlet if you already have Liferay running. I´ll also provide some links to books I read ... Let´s get started !


Getting started with Liferay and Liferay IDE


So ... first steps in Liferay 6. At first you need to download Liferay and choose an IDE. I am always using Eclipse, so I suggest you use Liferay IDE which is a very good extension for Eclipse.


Download Liferay (bundles with Tomcat) here : http://www.liferay.com/de/downloads/liferay-portal/available-releases


Unzip the file somewhere on your harddrive and start up the portal by double-clicking the "startup.bat" in the "bin" folder. Now it´s time to install the Liferay IDE plugin for Eclipse. Here is a fine tutorial to do so:


http://www.liferay.com/de/community/wiki/-/wiki/Main/Liferay+IDE+Installation+Guide


If you need an overview about all that is possible with the Liferay IDE, take a look at this fantastic page: http://www.liferay.com/de/community/wiki/-/wiki/Main/Liferay+IDE .


If you want to know how Liferay works and what it is capable of (from an administrators view), I can recommend the "Portal administration guide", directly from Liferay:


5.2 : http://docs.liferay.com/portal/5.2/official/liferay-administrator-guide-5.2.pdf

6.0 : http://docs.liferay.com/portal/6.0/official/liferay-administrator-guide-6.0.pdf


If you are into developing, you might want to take a look into the developers guide:


6.0 : http://docs.liferay.com/portal/6.0/official/liferay-developer-guide-6.0.pdf


What you have now is a configured Eclipse and Liferay that lets you develop portlets very easy. Unfortunately it´s only JSP Portlets, so ... how do you get ICEfaces to run ?


Geting started with ICEfaces 2.0


We will do this in two steps. Step 1 is to understand how ICEfaces applications are done, step 2 is to integrate ICEfaces into Liferay.


The best starting point to see how Eclipse and ICEFaces 2.0 work together is here: http://wiki.icefaces.org/display/ICE/Creating+ICEfaces+Applications+with+Eclipse


So - how do ICEfaces applications run within Liferay ? ICEfaces uses the portlet bridge which translates between the JSF and the portlet lifecycle. The portletfaces bridge is already included in ICEfaces 2.0, but if you want to take alook at the project, you can do it here: http://www.portletfaces.org/projects/portletfaces-bridge;jsessionid=663389E7787ED007F47E0ED3ED3AD419


This page also allows you to download a sample ICEfaces 2.0 portlet that you can just deploy and run in Liferay 6 (http://www.portletfaces.org/portletfaces-bridge/examples/jsf-2.0/icefaces-2.x-portlet).


If you want to take a look at the ICEfaces developers guide, take a look here: 

1.8: http://www.icefaces.org/docs/latest/ICEfacesDevelopersGuide.pdf

2.0http://wiki.icefaces.org/display/ICE/ICEfaces+2+Documentation



So - that´s it for today. I will try to write down a "step-by-step" introduction on how to create an ICEfaces 2.0 portlet tomorrow.



If you liked this tutorial it would be very nice, if you could click on some of the google ads you see on the right side. It helps me run this block and motivates me ;)

If you have any questions, feel free to leave a comment.


AlloyUI: Useful Links

Part 1   Part 2   Part 3   Useful Links   Useful Literature

Currently working a lot with AlloyUI, so I thought a collection of useful links is something I would really want and maybe some of my readers are looking for it, too.


If you have a useful link - drop it in the comments. I will update the page as often as possible.




Tag Lib Descriptions


Official Liferay wiki explaining some UI components (aui:form, aui:fieldset, aui:button, aui:button-row, aui:model-context,aui:input, aui:select, aui:option, aui:a, aui:field-wrapper, aui:legend, aui:column)


http://www.liferay.com/de/community/wiki/-/wiki/Main/Alloy+UI+Forms+(aui)#section-Alloy+UI+Forms+_28aui_29-More

http://www.liferay.com/de/community/wiki/-/wiki/Main/Alloy+UI+Forms+%28aui%29

Tutorials

http://www.abcseo.com/tech/liferay/alloyui-taglib

If you like this post it would be very nice, if you could click on some of the google ads you see on the right side. It helps me run this block and motivates me ;)

If you have any questions, feel free to leave a comment.

2/11/2011

Configuring AWStats

Not really a Liferay relevant post, but whenever you´re configuring a server like Tomcat or Apache you might come across AWStats analyzing your logfiles... I am currently trying to get AWStats to do what I want and one part of this is to provide AWStats a list of IP (ranges) that it shouldn´t index.


The property was found very quickly, it´s called "SkipHosts". But what do you do if someone gives you a CIDR notated IP Range ? I found two very helpful pages for that :


1) Get all the IP addresses from a CIDR notated IP Range


This page helps you to convert your CIDR notated IP Range to a range of IP Adresses:


http://bonomo.info/coyote/cidr-calculator.php


2) Convert the IP Range into a regular expression


Google helps you to get a regular expression for your IP range:


http://www.google.com/support/analytics/bin/answer.py?hl=en&answer=55572


That´s all - works like a charm, works with Liferay.



If you liked this tutorial it would be very nice, if you could click on some of the google ads you see on the right side. It helps me run this block and motivates me ;)

If you have any questions, feel free to leave a comment.

What I am reading


Some asked at linkedin what to read, when starting with LIferay. Well ... this is what I read at the moment:
While I am waiting for the final version of "Liferay In Action" I currently read "Liferay Portal 6 Enterprise Intranets" - it´s helping me migrating from Liferay 5 to Liferay 6 and makes understanding Liferay a little easier, I think.

2/10/2011

Is BING ignoring this Blog ?

Is it possible that BING is ignoring BlogSpot / Blogger ? I tried to goole for some of my posts but nothing came up. I even tried to submit it manually ... nothing happened ....


In the end I think I need to create a copy of my Blog that Microsoft is willing to index ....

2/09/2011

How to create an E-Mail Listener in Liferay6

An E-Mail Listener is done differently than a ModelListener I wrote about the last time. An E-Mail listener can´t be registered for an entity, it must be registered at the Liferay MessageBus. And this is how you do it:


Create the Listener Class


Implement the MessageListener class like this:



public class MailMessageListener implements MessageListener {


@Override
public void receive(Message arg0) throws MessageListenerException {
System.out.println("You got mail.");
}


}


Register the Listener


In your portlet, upon startup you can register the Mail Listener like this:



MailMessageListener listener = new MailMessageListener();

MessageBusUtil.registerMessageListener(DestinationNames.MAIL, listener);




That´s all you have to do. If you want to register your listener for other Destinations, take a look at the class com.liferay.portal.kernel.messaging.DestinationNames



If you liked this tutorial it would be very nice, if you could click on some of the google ads you see on the right side. It helps me run this block and motivates me ;)

If you have any questions, feel free to leave a comment.

Getting notified about model changes in Liferay

I came across the problem that I had to know how often the Users tend to update their profile picture. After a little research I found that the best way to do this are the Liferay Model Listeners. You define them like this:


Create your ModelListener class.


At first, create the class that will be notified about model changes and updates. You need to implement the ModelListener interface (com.liferay.portal.model.ModelListener) like this:


public class TestListener implements ModelListener<BlogsEntry> {
    [...]
}


This class allows to listen to all changes regarding Blog entries in Liferay. The following methods can be implemented:

  • onAfterAddAssociation
  • onAfterCreate
  • onAfterRemove
  • onAfterRemoveAssociation
  • onAfterUpdate
  • onBeforeAddAssociation
  • onBeforeCreate
  • onBeforeRemove
  • onBeforeRemoveAssociation
  • onBeforeUpdate



It should be pretty obvious what they do and when they are called.


Referencing in Liferay 5.1


In Liferay 5.1 you reference the model listener by adding the following to your lilferay-hook.xml:


<model-listener>
    <model-listener-class>de.test.TestListener</model-listener-class>
    <model-name>com.liferay.portlet.blogs.model.BlogsEntry</model-name>
</model-listener>




Referencing in Liferay 5.2 and later


In Liferay 5.2 and later you create a portal.properties file which contains your model listener and reference that in your liferay-hook.xml:


portal.properties


value.object.listener.com.liferay.portlet.blogs.model.BlogsEntry=de.test.TestListener




liferay-hook.xml


<hook>
    <portal-properties>portal.properties</portal-properties>
</hook>



If you liked this tutorial it would be very nice, if you could click on some of the google ads you see on the right side. It helps me run this block and motivates me ;)

If you have any questions, feel free to leave a comment.

2/08/2011

How to create a Scheduled Job in Liferay 6

If you want to have a cron job, a scheduled task or a scheduled task in Liferay 6, you can do the following:


Note, that all of this takes place in your portlet - no need to go for the ext environment.


Create the class that contains your business code


Implement the MessageListener interface and put your business code into the "receive" method.
import com.liferay.portal.kernel.messaging.Message;
import com.liferay.portal.kernel.messaging.MessageListener;
import com.liferay.portal.kernel.messaging.MessageListenerException;
public class TestJob implements MessageListener {
@Override
 public void receive(Message arg0) throws MessageListenerException {
 System.out.println("doing important work ...");
}}


Configure Your Portlet


Your Portlet needs to have the configuration for the TestJob. This can be done by adding the following to your liferay-portlet.xml:

<portlet-name>JobTestPorftlet</portlet-name><icon>/icon.png</icon>
<scheduler-entry>
  <scheduler-description>description</scheduler-description>
  <scheduler-event-listener-class>
    de.test.TestJob
  </scheduler-event-listener-class>
  <trigger>
    <cron>
      <cron-trigger-value>59 23 * * 0 ?</cron-trigger-value>
    </cron>
  </trigger>
</scheduler-entry>


This will run your job once a week sundays at 23:59. If you want the simple approach you can replace the cron time by this:

<simple>
  <simple-trigger-value>1</simple-trigger-value>
  <time-unit>minute</time-unit>
</simple>

This will run your job once the server is started and then every minute.


If you liked this tutorial it would be very nice, if you could click on some of the google ads you see on the right side. It helps me run this block and motivates me ;)

If you have any questions, feel free to leave a comment.