Blogs

Blogs

Tip of the Day - Pointer Portlets

Sometimes you need to perform actions which relate directly to your Liferay portal and your site structure. In some cases getting the handle on the layout needed might be a bit tricky though. You might query it with certain parameters, maybe using expando attributes or something similar.

One clever little trick we’ve done on some of our projects is using pointer portlets. In this context the word “pointer” means that the portlet is used as a way for developer to get a handle on the layout it is placed on. This allows you to customize the behaviour of the portal dynamically by moving the portlet from layout to another.


Once you have your pointer portlet name figured out, getting the layout is a walk in the park

One thing we've used pointer portlets for is to redirect users more flexibly. What is needed is a couple of pointers, one for each scenario where you need to redirect the users differently. When you need to send the redirect and you know which portlet is needed, you can use Liferay’s utility methods to get the layout where the said portlet is on. After this, sending the redirect is as simple as tying your shoelaces.

To take the concept a bit further, we’ve used pointer portlets with some scheduled processes as well. For instance, we had a little script which created layouts according to some data fetched over a web service. We could use the pointer portlets to give the script a handle to the layout under which the new layouts were to be generated. And what is even more awesome is that when we made the pointer portlet configurable, we could also alter the dataset fetched to create the layouts and even if the pointer was active in the first place. We coupled this with simple layout prototypes (defining them in portlet configuration as well) to create a set of uniform layouts dynamically where we wanted to. The solution was portable and easy to use.


Creating your pointer portlets configurable allows for further flexibility in using them

You might think of another ways to take advantage of this little concept. The basic idea remains the same, you have your pointers placed on the layouts you need a handle on. When the time comes, you’re just a couple of queries away from where you want to be.