11/12/2014

Liferay 7 : Elasticsearch vs. SOLR

Liferay 7 will switch from lucene to elasticsearch as the standard search provider. But what is elasticsearch and why is it a good idea to have it in your liferay installation ? And where´s the difference to SOLR, which is already a good alternative and can be integrated into Liferay pretty easily ?
Let´s take a look at the google search queries from the last years to see how many people care for which search technology.



As you can see, elasticsearch surpassed SOLR in the last year. Question is: why ? Let´s talk a little about both technologies to see if there is an actual technological explanation for what we see here. Note: There are so many ways to compare both technologies that there is an own site just for that. If you want to dig down really deep I would suggest taking a look here: http://solr-vs-elasticsearch.com/

This video is a nice introduction to SOLR:




And this one is a good one about elasticsearch:





Consider having more requirements to your liferay search then just providing a search field. Consider specifying how your search behaves, which data types will be indexed and consider a clustered, fail-save environment with a lot of data.

If you have a lot of data, that you could also group into several indexes then you need "shards". A shard is an index of its own that can be accessed by your search provider. SOLR and elasticsearch allow you to define shards and also allow you to define schemas for each shard. Using shards you can define a shard for the users, another one for documents and a third one for car information. All shards can have different attributes that you can search for. Those attributes will be defined either out of the box (SOLR and elasticsearch support this) or you can write your own finegrained schema file. This approach is my choice for huge liferay projects.

You can even distribute your shards over several machines. Elasticsearch does this ootb, SOLR has the so called SOLRCloud, that supports distribution.

Elasticsearch also allows you to define replicated shards and thus supports securing your applications search data a little better then SOLR does. Both search providers allow you to process JSON documents, SOLR also allows you to work with XML or CSV.

Elasticsearch is made for the cloud, and it supports big data integration with the "ELK stack" - Elasticsearch, Logstash, Kibana, as a Big Data analysis solution. Visit the following sites to learn:

Logstash: http://www.elasticsearch.com/products/logstash/
Kibana: http://www.elasticsearch.com/products/kibana/

While going through all the features that both search providers have, one could get the impression that there is no killer argument for one side of the "search battle". Both SOLR and elasticsearch can be used to perform the same things. While it is a very good idea from the liferay crew to integrate elasticsearch instead of a simple lucene index, there is no technological reason not to use SOLR. Elasticsearch seems to be a little easier to use out of the box and it is definetely a trending topic. Those might be two key points that lead to liferay´s decision to integrate it instead of SOLR.

So the bottom line is: Take the technology you prefer, there is no need to migrate to elasticsearch as long as you don´t need one of the central features they´re offering that SOLR doesn´t have. For all those of you who never thought about the search technology used by liferay under the hood: You will be able to distribute your indexes and have a much faster search then before.

Since elasticsearch is based on lucene it will be interesting to see how and if a migration will be possible.


Do you need expertise in SOLR, elasticsearch and / or liferay ? 
Just Contact me !

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

11/11/2014

Liferay 7 : Web Content Diffs

One very nice new feature of the upcoming Liferay 7 will be Web Content Diffs. Like a SVN history comparison tool it will allow you to compare two web content versions, thus making approving new web content versions much easier. This new feature can be used in the workflow portlet and in the web content admin section. If you want to read more, then you can read here:

Web Content Diffs should look something like this:



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.

11/10/2014

Liferay 7 ... first look at M2

Just started to take a look at Liferay 7 M2. So far the only issue I had was that I had to upgrade to Java 7. I will write some more blog entries in the next days about Liferay 7 and all its new features like
  • Bootstrap 3
  • ElasticSearch 
  • Web Content Diffs
  • Develop complete portlet as OSGi modules
  • ... stay tuned !

You can find all my posts about Liferay 7 here.












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

11/05/2014

Embedding a Liferay Portlet in a Theme

If you want to include a portlet in a liferay theme you can just use the following snippet:
$theme.runtime("your-portlet-id")
Your-portlet-id can be a static id or an instance id.

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

Geocoding with Primefaces

Primefaces offers an official primefaces google maps implementation. With the new primefaces 5.1.2 it also allows you to use geocode with the following two new methods:
  • geocode(address)
  • reverseGeocode(lat, lng)

This is an example from the official primefaces showcase:
 <p:gmap id="geoGmap" widgetVar="geoMap" center="#{geocodeView.centerGeoMap}"type="ROADMAP" model="#{geocodeView.geoModel}">
    <p:ajax event="geocode" listener="#{geocodeView.onGeocode}" update="@this" />
 </p:gmap>

The java code for the normal geocode request looks like this:
public void onGeocode(GeocodeEvent event) {
List<GeocodeResult> results = event.getResults();


if (results != null && !results.isEmpty()) {

 LatLng center = results.get(0).getLatLng();
 centerGeoMap = center.getLat() + "," + center.getLng();

 for (int i = 0; i < results.size(); i++) {

  GeocodeResult result = results.get(i);
  geoModel.addOverlay(new Marker(result.getLatLng(), result.getAddress()));

  }

 }

}
Continue reading here: http://blog.primefaces.org/?p=3339 

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

Liferay IDE 2.2 has been released

Those of you who work with liferay every day will like the news that the Liferay IDE has been updated to 2.2.  Features include:


  • Complete AlloyUI integration including type inference for AlloyUI, YUI and jQuery (called tern.java). So for the first time ever you can press SPACE+STRG to get code completion for alloyUI script. You´ll get code assist for all methods and objects, including those for static liferay methods.
  • The same goes for jquery: You will get code assist for jQuery, too.
  • Better CSS Support
  • A lot more of those improvements, including action method completion !
  • Eclipse Assistance to navigate between generated Service classes, Wrappers and JSPs.
  • Faster and rewritten Eclipse Editors
  • Feature to import liferay preferences from workspace to another
  • ... and many many more.

Try it out and visit the official blog post here:





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

11/04/2014

How to show the liferay search portlet in a liferay theme

To Include the liferay serach portlet in a liferay theme, you can just add the following :
<div id="portal-search" style="float:right">             
  $theme.search()
</div>

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

JSF 2.3

JSF 2.3 has been approved (https://weblogs.java.net/blog/mriem/archive/2014/09/23/jsf-23-has-been-approved) and the work on the new iteration has begun.

The specification summary reads as follows:
This JSR aims to improve the clarity of the existing JavaServer Faces
(JSF) specification and introduce a small, targeted set of new features
as directed by community contribution. To summarize, JSF 2.3 will target small scale new features, community driven improvements, and platform integration.

These are the new features we can expect:
- Ajax method invocation: Ability to make direct CDI method invocations from Ajax
- Multi-field validation
- Ability to @Inject FacesContext
- EL Performance Optimizations
- Cross-form Ajax Clarifications


The final release should be in Q3, 2016, so we might stick a while with JSF 2.2 ...

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

11/03/2014

Primefaces and responsive layouts

One of the mayor buzzwords in the last years was "resposive webdesign". What that means is that your webpage responds to the screen that shows the page. A responsive page will have a different layout depending on whether it is shown on a smartphone, a tablet or a PC. This also affects the individual components that make up the page. One of the key features for liferay to support this are responsive themes, created by popular technologies like bootstrap (yes, bootstrap rocks :) ). If you want to know more about responsive design, you can read here: http://en.wikipedia.org/wiki/Responsive_web_design

But what about JSF and primefaces? Good, that I just came across a blog post on the official primefaces blog that explains responsive design for the primefaces DataTable. DataTables don´t leave us much choices when it comes to displaing them on a mobile device: Either we restructure the way we display the data or we don´t show all the data.

The DataTable component uses the following two approaches to deal with changing screen sizes:

Column Toggle

Column Toggle simply means: "Decide which columns are most important to your users and leave away the rest". You, as a developer can prioritize the columns of your DataTable. The columns that have the lowest priority will not be shown when the space on the screen is too small to show them all.

Reflow Mode

Reflow mode transforms the primefaces DataTable into a a list of data. All the data is shown but instead of a horizontal layout it is displayed vertically. Use this if all the data you show is important and should not be left away.

Those features are included in primefaces 5.12, the blogpost can be found here: http://www.primefaces.org/showcase/mobile/dataTable.xhtml


This small introduction to responsive design for primefaces shows that primefaces is still the No 1. choice when it comes to JSF frameworks and it is adressing the issues people care about. Before you simply code your web app with several JS frameworks and then realize that you need a connect to a backend ... take a look at primefaces and see how it integrates responsive web design with reliable and robust java code.


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

10/30/2014

AlloyUI 3 has been released

Liferay just announced, that AlloyUI 3 has been released. It will be the last YUI - based release before switching over to jQuery with AlloyUI 4.

The AlloyUI (http://alloyui.com) website has already been updated with new examples and tutorials, and you can find all the release info here:

https://www.liferay.com/de/web/zeno.rocha/blog/-/blogs/alloyui-3-released-bye-bye-yui


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

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.

10/29/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.

9/09/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.

9/05/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.

9/04/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.

4/19/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.

2/06/2014

How to put your document library folder under workflow control programmatically

If you want to create document library folders (dlfolder) programmatically, you can do this very easy by calling
DLFolderLocalServiceUtil.addFolder(userId, groupId, groupId, false, 0, "Folder title", "Folder description",false, new ServiceContext());
That´s just one line of code and you´re done. But what if you want to put your folder under workflow control? Liferay offers the possibility to connect assets in your folders to specific workflows. So as soon as you upload a basic document for example, the workflow will be started.  You can do that manually when you select your folder and click on "Edit":



Wouldn´t it be nice it that could be done programmatically ? Liferay source code comes to the rescue ! This is how they do it. First, set the file entry types override:
dlFolder.setOverrideFileEntryTypes(true);
dlFolder = DLFolderLocalServiceUtil.updateDLFolder(dlFolder);
Then you need to query the DLFileEntryType table for the FileEntryType you want to set up a workflow for. Next, you need to set the DlFileEntries for the folder:
long[] fileEntryTypeIds = new long[] { basicDocumentType.getFileEntryTypeId() };
DLFileEntryTypeLocalServiceUtil.setDLFolderDLFileEntryTypes(dlFolder.getFolderId(), fileEntryTypeIds);
Next is a query to get the process definitions you want your folder and the fileEntryType to connect with:
List<WorkflowDefinition> activeWorkflowDefinitions = WorkflowDefinitionManagerUtil.getActiveWorkflowDefinitions(companyId, "Your Process Name", 0, 100, null);
And last but not least you need to add a workflow definition link:
WorkflowDefinitionLinkLocalServiceUtil.addWorkflowDefinitionLink(userId, companyId, groupId, 
DLFolderConstants.getClassName(), dlFolder.getFolderId(), basicDocumentType.getFileEntryTypeId(),  name, version);


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.

2/03/2014

How to show a JSP full-screen in liferay

Just answered this question to a developer on stackoverflow, so I just wanted to share it in my blog. If you want to access a JSP in full-screen mode, without showing anything of the liferay portal the JSP is deployed in, you can do the following:


Create a portlet and inside the portlet, create a servlet. This has the nice advantage that you can access your JSP by a URL like http://localhost:8080/your-portlet/your-servlet. Just think about a nice name and you will come up with a dozen business cases. Anyway ... inside your servlet you can now do a forward to your JSP and this JSp will then be displayed in full-screen. Please note that now you don´t have access to the liferay request context - no themeDisplay for example.



Creating the forward in your Servlet is pretty simple. Just add the following:

String forwardJSP = "/your-jsp.jsp";
RequestDispatcher requestDispatcher = getServletContext().getRequestDispatcher(forwardJSP);
requestDispatcher.forward(request,response);

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.

1/15/2014

Comparing Primefaces, ICEFaces and Richfaces with Google Trend

One thing that I´ve notices in the last two years was that primefaces pretty much eats up all the other JSF frameworks. Nearly all my clients moved away from ICEFaces towards Primefaces. So I just entered some data into Google Trends which shows us the interest of people into those technologies. As you can see, primefaces now has more than double the interest compared to ICEFaces and Richfaces combined. Well I know that it is only the search queries that people entered into google but I think that it exactly shows my work experience for 2012 and 2013: Everyone is switching to primefaces now.

Looking for primefaces support ? Contact me !

1/10/2014

How to open a modal dialog in Liferay

If you want to create modal dialogs (a popover) in liferay you can use the AlloyUI modal component. This component allows you to refer to complex DIVs and pop them over the current window. You can do this without having to reference any additional libs.

Just add this and you will see the content of the 'popupContent' popping up:


var modal = new A.Modal(
{
bodyContent: A.one('#popupContent'),
centered: true,
headerContent: '<h3>This is a header </h3>',
modal: true,
render: '#modal',
zIndex: 1100,
height: 700, 
width: 950
}
).render();

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.

1/08/2014

How to setup the activity monitoring console for Talend

I started using Talend 5.3 a few days ago and one of the things I´ve spend most of my time with was the activation of the activitiy monitoring console (AMC). Even though there is a lot of configuration out there, there is no clean documentation what to do when you have a clean Talend 5.2 installation.


This is what you have to do to activate and use it:

1) Create database tables
2) Activate it in your Talend Studio
3) Activate it in your Talend Studio AMC perspective
4) Activate it in the Talend Administration Center (TAC)


Create the AMC database tables


The AMC tables are not created by default. They don´t exist and you have to create them manually to use them. You could use files instead but then you can´t use it in your TAC´s dashboard which only works with database tables.

Thankfully, Talend already has a tutorial that shows you how to create the database tables. You just have to know where it is. Here it is :


When you´ve finished this tutorial, you will have three database tables "logcatcher", "statcatcher" and "flowmetercatcher". LogCatcher is responsible for catching Exceptions and Warnings. Use it to build your own logging service for example. StatCatcher contains logging information for the processes you run.
FlowMeterCatcher contains information for specially monitored connections (like database calls).

Activate AMC in your Talend Studio

To activate AMC in your Talend Studio you can either activate it in your project or activate it for one individual jobs only.To activate it for the complete project please click on
File -> Edit project properties -> Job Settings -> Stats & Logs.
Select all checkboxes  so that Logs, Statistics and volemetrics can be catched. Check "In Database" and configure the database connection that you want to use.

After that please check that the AMC is active for the projects that you´re working on. This can be done by activating "Use project settings".

Alternatively you can activate the AMC for several jobs only. Look under "Stas and Logs" in your job view. If you configured AMC in the project it is sufficient to check "Use project settings" here,

After you´ve done that, your Talend Studio is now able to provide monitoring infirmation. What you need to do now is to configure your Talend Studio to visualize this information.

Activate AMC in your Talend Studio AMC perspective

Enter the AMC perspective in your Studio. It doesn´t yet show logging infos and needs to point to the three database tables we´ve created earlier. Please click the following : Fenster -> Benutzervorgaben -> AMC -> Datasource Type


Check "Database" and click on "Add". Give it a name and configure the database so that it accesses the AMC Data.

After that you have your AMC Information visualized in your Talend Studio. This is something that you need to do for every user of the Talend Studio: It is not possible to synchronize it over SVN.

Configuration of the Talend Administrative Console

The Talend Administrative Console (TAC) is able to show just the same data the Talend STudio does. To be able to display it, you need to configure your database connection, first.
Click on Dashboard -> Connections and select "Add".Enter all database connection details , including the database tables.
If this doesn´t yet work, then please check if you have a "localhost" URL under Settings -> Configuration -> Dashboard.  If so, please replace it with your actual server URL or server name.

After doing so, you should now see the AMC in the TAC.




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.

1/07/2014

How to create AlloyUI reusable methods

When you are writing as much AlloyUI code as I do, you will certainly come to the situation where you want to reuse your code. Gladly, YUI3 (the foundation for AlloyUI) allows that. You can create your own modules and register them statically so you can call them from different parts of your application.


The key part is the "add" function.  It allows you to register your new module with all the methods, that you want to add. 

YUI.add('your-registered-module', function (A) {
  A.YourModuleObject = {
    yourMethod: function () {
      alert('Hello World');
  }
});

Do this at the beginning of your file and you can add your method in your code using this:
YUI().ready(
'your-registered-module',
  
  function(A) {
 A.one('#myButton').on('click', function(event) {
  A.YourModuleObject.yourMethod();
  });
Explanation: In this case we attach our hello world method to a button. When the button is clicked, our reusable method gets called and send the alert.

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.

1/06/2014

How to render a WebContent programmatically

Sometimes you might want to render a WebContent programmatically. Maybe because you want to include it in a portlet or maybe you are not able to use the liferay journal-article taglib. There is a very easy solution that you can use in every JSP portlet. I took it from the taglib, so the credit doesn´t really belong to me ;)


JournalArticleDisplay articleDisplay = 
JournalContentUtil.getDisplay(groupId, articleId, templateId, null, languageId, themeDisplay, articlePage, xmlRequest);

<%= RuntimePortletUtil.processXML(application, request, response, renderRequest, renderResponse, articleDisplay.getContent()) %>


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

How to directly link to a liferay web content

When you want to show Web Contents to your visitors and have a meaningful URL  (one that has the article´s title in it), then you should check out LIferay´s Display Pages. It allows you to assign WebContents statically to a page and then access that page through a link that has the WebContents title. Normally WebContents are not bound to any page at all, but Display Pages allow just that. This will only work in Liferay 6.1 and above. This is how you do it :

First you'll need to create a page and assign the asset publisher portlet to it. You only have to change one part in the configuration and that is  you'll need to check the box next to the option that sets the asset publisher as the default publisher for the page. 

When you are creating your Web Content you now have the possibility to select a Display Page (see right side menu).
Select the page you just created. After the WebContent has been published, you can access the page with the WebContent´s title. Example: http://localhost:8080/-/this-is-a-webcontent .

Should make SEO much easier ...