Donnerstag, 30. Oktober 2014

BeanLocator has not been set for servlet context

If you get an exception like this:

javax.portlet.PortletException: com.liferay.portal.kernel.bean.BeanLocatorException: BeanLocator has not been set for servlet context

then take a look at the portlet you´ve written. If you portlet´s name doesn´t end with "portlet" then this might be the reason for your Exception. Create a new portlet with the correct name, import all your sources and try again.

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

Mittwoch, 29. Oktober 2014

Showing Web Contents in a Liferay Theme

If you want to render a WebContent as part of your theme, you can do the following. Create your theme as always, and put the following inside your init_custom.vm file:


#set ($journalArticleLocalService =$serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleLocalService"))

#set ($journalContentUtil =$utiLocator.findUtil("com.liferay.portlet.journalcontent.util.JournalContentUtil"))

#set ($web-content-display-article-id = "your-article-id-here")

#set ($web-content-display-article =$journalContentUtil.getContent($group_id, $web-content-display-article-id,null,"$locale",$theme_display))


If you like 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.

Dienstag, 9. September 2014

Adding the AlloyUI hover effect to all your nodes

This is a little extension of the post about creating a hover effect in AlloyUI. If you want to apply the hover effect to, say 20 nodes on your page, you can use the following snippet. It queries all "hover-me" nodes on the page and applies the hover effect to them.


If you like 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.

How to create a hover effect in Alloy UI

AlloyUI is the scripting language build right into liferay that you can use to create fantastic looking responsive UIs that look exactly like liferay´s own portlets. This scripting language is built on top of YUI3 by yahoo. So whenever you don´t find something in AlloyUI´s examples page (http://alloyui.com/), you might want to check YUI´s page (http://yuilibrary.com/).
Today I want to show you a nice fade in / fade out effect that I am using in some of my portlets. As soon as you hover over the "hover-me" div, the "hello world" button will appear. You can use this example directly in liferay : no additional libs needed ! Have fun :)

This is just a text
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.

Freitag, 5. September 2014

Primefaces 5.1 teaser Video

For those of you who are eager to see the new Primefaces 5.1 features ... take a look at this video. It shows some of the new components that will be available in Fall 2014. 





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

A JasperReports Liferay Portlet (1)

Lately I´ve been working with JasperReports. I´ve included it in a liferay portal so that the user will be able to include reports about all the groups he has on his webserver. When you´re working with enterprise open source software like liferay, you will see that a lot of the software is used together: Liferay with JSF with Activiti Workflows, maybe a connection to Talend, JasperReports as the reporting server and Alfresco as a document server. That´s why I´ve decided to add my JasperReports experience to this blog and not create a new one.

So this will be the first post in a series on how to use JasperReports. But beware: All posts will still have a strong liferay focus. I´m not using the JasperReports Server and I am not building a stand-alone reporting solution.

What is Jasper Reports ?

JasperReports is a reporting solution that connects to almost any dataSource out there and delivers good-looking reports in almost any format. My goal will be to get data out of liferay services and present them as a PDF document for the users to download.

To create reports in your portal you will need the following:

1) The JasperReports Library (Link)

This is a set of JARs that contain JasperReports. You can include them in your portlet by copying them into your WEB-INF/lib folder for now. Basically those JARs are all you need if you´re keen to write your reports in XML.

2) The JasperReports iReport Designer (Link)

That´s a "drag and drop" GUI that creates your diagrams. It´s free and you should use it if you want to save some time. Please download and install it.


Out first goal will be to create a Report with the iReport Designer, put it into our portlet, equip the portlet with the JARs we need and then download the report in liferay. Open iReport designer and create a new blank report. This will be very simple "hello world" report that we will just use for demonstration purposes. Add a "Static Text" Element to the header section and save the document. Click on "Compile report" to produce a compile jasper file.



Using a jasper file instead of a jrxml file has the advantage of not having to compile it when we run our code. This saves time and ressources. 

If we are talking about integrating jasper reports into liferay we will start with a simple example: A portlet displaying reports. The simplest approach is to create a portlet with an iFrame that points to a servlet delivering the report. 


//get input stream to jasper file
InputStream input = Thread.currentThread().getContextClassLoader() .getResourceAsStream("report1.jasper");
final FileBufferedOutputStream fbos = new FileBufferedOutputStream();
//load report
JasperReport report = (JasperReport) JRLoader.loadObject(input);
JasperPrint jasperPrint = JasperFillManager.fillReport(report, parameters, null);
//export report as PDF
JRExporter exporter = new net.sf.jasperreports.engine.export.JRPdfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, fbos);
exporter.exportReport();

//write pdf to servlet output stream
ServletOutputStream ouputStream = response.getOutputStream();
response.setContentLength(fbos.size());
fbos.writeData(ouputStream);
fbos.flush();
fbos.close();
fbos.dispose();
ouputStream.flush();

Now all you have to do, is to decide whether you want to show your report inline in an iFrame or downloadable via a link. Have fun :)


If you like 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.

Donnerstag, 4. September 2014

How to start a liferay scheduled job programmatically

You can start liferay scheduled jobs via configuration in the liferay-portlet.xml file (see here) and you can stop them programmatically (see here).  And this is how you start them:

public static void startProcess(String name, String portletId) {
  SchedulerEntry schedulerEntry = new SchedulerEntryImpl();
  schedulerEntry.setDescription("This is a programatically created process");
  schedulerEntry.setEventListenerClass(Your-Listener-Class.class.getName());
  schedulerEntry.setTimeUnit(TimeUnit.MINUTE);
  schedulerEntry.setTriggerType(TriggerType.SIMPLE);
  schedulerEntry.setTriggerValue(30);

 try {
   SchedulerPropertiesLocalServiceUtil.turnOnProcess(Your-Listener-Class.getName());
   SchedulerEngineHelperUtil.schedule(schedulerEntry, StorageType.MEMORY_CLUSTERED,
 portletId, 0);
 } catch (SchedulerException e) {

   _log.warn(e);
 }
 }


If you like 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.