Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Liferay alert user when portlet not present

Suppose portlet X is deployed to Liferay and has a friendly URL mapped. Suppose a user enters the Liferay Portal via a the mapped URL but the portlet is not present in the portal - it's deployed but not added to the page.

My problem is that when the user uses the mapped URL nothing happens - the portal gives no visual feedback, that the target portlet is not present.

How can I change that? I need some kind of an alert / notice to the user...

-- edit --

I need not use a second portlet to check the presence of yet another portlet.

Kindest regards,

like image 272
Queequeg Avatar asked Feb 08 '12 09:02

Queequeg


2 Answers

AFAIK, there is no natual way to make that happen. A portlet need not always be installed on a page. So, the behaviour is quite normal.

One rather hacky solution I could think of:

  1. Get hold of the ThemeDisplay object in a JSP using <liferay-theme:defineObjects /> which would expose the implicit object themeDisplay in the JSP scope.

  2. Get hold of the type settings string using:

    String typeSettings = themeDisplay.getLayout().getTypeSettings();
    
  3. Type settings will have values like the below:

    layout-template-id=foobar_2column
    sitemap-include=1
    column-1=foo_WAR_barportlet,abc_WAR_barportlet,56_INSTANCE_K4Vv,
    column-2=baz_WAR_xyzportlet,
    sitemap-changefreq=daily
    
  4. So if you have a non-instanceable portlet with ID foo inside WAR file bar, the portlet's unique ID on the layout will be foo_WAR_barportlet.

  5. Once you know the portlet ID that you're expecting to be present, it's just a matter of string contains check.

    <% if(!typeSettings.contains("foo_WAR_barportlet")) { %>
        <h3 style="color: red">Alert! Portlet foo_WAR_barportlet not installed.</h3>
    <% } %>
    

You can do the above steps even inside a theme, but you'll have to do it in Velocity instead of Java then. Hope that helps.

EDIT

You can add this line inside your portal_normal.vm

#if(!$layout.getTypeSettings().contains("foo_WAR_barportlet"))
    <h3 style="color: red">Alert! Portlet foo_WAR_barportlet not installed.</h3>
#end
like image 152
adarshr Avatar answered Oct 21 '22 23:10

adarshr


Yes you can achieve that using Inter-portlet communication, for notifying the user whether the portlet is added to the page or not. you need to create another portlet(lets call it ListenerPortlet) which by default sits on the page.

you can add the Listener portlet to the theme, so that it is by default added to every page.

Now, when you add your portlet to your page, your portlet should trigger a client-side javascript event and notify your Listener portlet that your portlet is added to your page.

From your portlet call,

Liferay.trigger(eventName, data)

and bind your Listener portlet to the event

 Liferay.bind(eventName, function, [scope]) //make the scope as page

This way your Listener portlet will know if your portlet is added to the page or not. and you can display a message to the user if the portlet is not added.

For further reference check the IPC

and more specifically client-side Inter portlet communicaton

like image 31
Rajesh Pantula Avatar answered Oct 21 '22 21:10

Rajesh Pantula