Aug 21, 2013

[Solved] Task cannot continue because ECJ is not installed — in Eclipse ant

I know this is known error but still I put it here as it could be helpful.
   
Task cannot continue because ECJ is not installed.

ECJ was automatically installed.

Please rerun your task. Total time: 1 second    

If you get above error in your IDE, just follow below steps to resolve it.   

  1. In Eclipse, Go To Window --> Preferences --> Ant -> Runtime
  2. Select "Ant Home Entries (Default)"
  3. Add External JAR (ecj.jar)  from your plugin-sdk->lib folder
  4. Ant should now be able to compile from your build.xml

Jul 23, 2013

Embed portlet in theme

  • Create a portlet with any name you want, EX. "portlet-embedded".
  • Write your code in portlet (view.jsp) to be displayed.
  • After adding your code to the portlet deploy the portlet so it is available for to use in theme.
  • Embedding portlet in theme
    • Open the velocity template file in which you want to embed the portlet.
    • Add below code in velocity template.
Code snippet

<div id="embedded-test-div">
$theme.runtime("headercart_WAR_headercartportlet","queryString", $velocityPortletPreferences.toString())
</div>

  • The Red marked line is for to embed a portlet in to theme
    • name="headercart_WAR_headercartportlet" the name of your portlet to be embedded with.
    • queryString="" give queryString if any other wise blank as it is optional.
    • You can set preferences using velocityPortletPreferences string or give blank this is also optional.
  • You are done now deploy the theme and you will get the porltet embedded with theme.
  • For more information do visit the link

Jul 4, 2013

Example of Embedding a portlet in to a web content portlet


  • Create a portlet with any name you want, EX. "portlet-embedded".
  • Write your code in portlet (view.jsp) to be displayed.
  • After adding your code to the portlet deploy the portlet so it is available for to use in web content.
  • Adding web content on page
    • Go to dock bar and select Add button and click Web Content Display so it's add Web Content Display portlet on to your page.
    • After adding web content to page now add the content to web content display by clicking Add Web Content button of Web Content Display portlet. 
Code snippet

   <div id="test-div">
<div id="testdata">
Lorem Ipsum is simply dummy text of the printing
and typesetting industry. Lorem Ipsum has been the
industry's standard dummy text ever since the 1500s,
when an unknown printer took a galley of type and 
scrambled it to make a type specimen book. 
</div>
<div id="embedded-test-div">
            <runtime-portlet 
name="portletembedded_WAR_portletembeddedportlet" 
instance="" queryString=""/>
</div>
</div>


  • The Red marked line is for to embed a portlet in to web content 
    • name="portletembedded_WAR_portletembeddedportlet" the name of your portlet to be embedded with.
    • instance="" give instance name other wise blank.
    • queryString="" give queryString if any other wise blank.
  • After adding this save the web content with proper name.
  • So it display the web content with your data plus the portlet with their data as shown below. 





Jun 13, 2013

IPC using client side java script


  • Introduction

    The client-side mechanism to communicate portlets is based on events,uses events instead of direct js calls accross portlets is very important
    since it's not possible to know at deployment time which other portlets will be available in a given page.

    By firing/triggering an event one portlet just notifies that something has happened,
    and then one or more of the other portlets in the page might be listening and act accordingly.

    Code snippet:

    Example: Updating a label inside second-portlet using a link provided in the first-portlet.

    snippet-1: insert the below code in to docroot/view.jsp of first-portlet.

    <script>
    jQuery(
            function () {
              jQuery('a.change_label').click(
                function(event) {
                  Liferay.fire('changeLabel');
                  return false;
                });
              jQuery('a.remove_label').click(
                function(event) {
                  Liferay.fire('removeLabel');
                  return false;
                });
           }
    );
    </script>
    <a class="change_label">Click here to fire event</a><br/>
    <a class="remove_label">Remove label on second portlet</a>


    snippet-2: insert the below code in to docroot/view.jsp of second-portlet.

    <script>
            Liferay.on(
               'changeLabel',
               function(event) {
                 jQuery('label.info_label').html('Event fired on first-portlet');
               }
            );
            Liferay.on(
               'removeLabel',
               function(event) {
                 jQuery('label.info_label').html('');
               }
            );
                  
    </script>
    <br/><label class="info_label" />

    Deploy these portlets and check how they work.

    Congratulations !!

    NOTE:

     Liferay.trigger(eventName, data)
     Liferay.bind(eventName, function, [scope])
    These methods have been deprecated in Liferay 6 in favor of
     Liferay.fire(eventName, data)
     Liferay.on(eventName, function, [scope])

     For more Information about this please check this link