Milen Dyankov

on a mission to help developers build clean, modular, and future-proof software

Mobile device detection in Liferay 6.1

May 29, 2012 | 1 Minute Read

I’m still getting a lot of questions about how to use the multi-device extension in Liferay 6.1. The answer is, you don’t have to! The code was contributed to Liferay and it’s now available OOTB in Liferay 6.1.

The following comparison table will give you a better idea of what went where:

 Feature Liferay 6.0  Liferay 6.1
look and feel change logic, generic data model and "extension points" for other plug-ins. multi-device-ext plugin integrated into Liferay's core. No need to install additional plug-in
Device recognition based on WURFL wurfl-web 6.0.5.x plugin (does not contain WURFLD DB) wurfl-web 6.1.0.x (available under AGPL license, due to the fact WURFL itself switched to AGPL, as part of Liferay's official plug-ins. It contains the WURFL's database!)
Building device rules and applying actions to matched rules device-rules-hook-6.0.5.x plugin Integrated into Liferay's core. No need to install additional plug-in (Provides somewhat different approach for managing rules and rule groups. Rules conditions simplified/limited to OS chooser and "is tablet" combo box.)

So, to use device detection in Liferay 6.1, all you need to do is download and install the official wurfl-web plugin!

If you get exception like this :

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "liferay/hot_deploy-1" java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder
at org.slf4j.LoggerFactory.getSingleton(LoggerFactory.java:230)
at org.slf4j.LoggerFactory.bind(LoggerFactory.java:121)
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:112)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:275)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:248)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:261)
at net.sourceforge.wurfl.core.resource.XMLResource.<clinit>(XMLResource.java:59)
at com.liferay.portal.mobile.device.wurfl.WURFLHolderImpl.getWURFLDatabase(WURFLHolderImpl.java:140)
at com.liferay.portal.mobile.device.wurfl.WURFLHolderImpl.initialize(WURFLHolderImpl.java:73)
at com.liferay.portal.mobile.device.wurfl.messaging.WURFLDeploymentMessageListener.doReceive(WURFLDeploymentMessageListener.java:52)
at com.liferay.portal.kernel.messaging.BaseMessageListener.receive(BaseMessageListener.java:25)
at com.liferay.portal.kernel.messaging.InvokerMessageListener.receive(InvokerMessageListener.java:65)
at com.liferay.portal.kernel.messaging.SerialDestination$1.run(SerialDestination.java:101)
at com.liferay.portal.kernel.concurrent.ThreadPoolExecutor$WorkerTask._runTask(ThreadPoolExecutor.java:669)
at com.liferay.portal.kernel.concurrent.ThreadPoolExecutor$WorkerTask.run(ThreadPoolExecutor.java:580)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.ClassNotFoundException: org.slf4j.impl.StaticLoggerBinder
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1688)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1533)
... 16 more

Then:

  • download slf4j from http://www.slf4j.org/download.html
  • unzip it and copy slf4j-log4j12.jar to <LIFERAY_HOME/tomcat-7.0.23/webapps/wurfl-web/WEB-INF/lib folder
  • restart Liferay

Once you have this installed you can go ahead and define your rules. The following video demonstrates how: