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.

How to stop a liferay scheduler programmatically

As you know, liferay allows you to create schedulers to do repeatative tasks, like import or synchronization jobs.  If you don´t know that, then you might want to take a look here: Creating Liferay Scheduled Jobs .

Fot those of you who do know that it might be interesting to know how to forcefully stop such a started process programmatically. You never know when you need to stop the process.  This is how you do it :

try {
  scheduledJobs = SchedulerEngineHelperUtil.getScheduledJobs();
  for (SchedulerResponse resp : scheduledJobs) {
    if (resp.getJobName().equalsIgnoreCase(name)) {
      String groupName = resp.getGroupName();
      StorageType storageType = resp.getStorageType();
      _log.info("Unscheduling :" + name);
      SchedulerEngineHelperUtil.unschedule(name, groupName, storageType);
    }
 }
 } 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.

Samstag, 19. April 2014

How to show a portlet on every page / layout

If you want to show a portlet on every layout in our portal, you can simply add it´s portlet id to your portal-ext.properties.
Do it like this:

layout.static.portlets.all=your-portlet-id
Once done, your portlet should be available on all pages. If you want to prevent users from deploying portlets manually you can set the following property in your liferay-portlet.xml:


<system>true</system>

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.