Thursday, December 27, 2012

Removing the Portlet Borders Through out Portal From Theme Level , Liferay

To Remove the Portlet Borders from theme Level ,

You need to write a simple code in "liferay-look-and-feel.xml " file which is in ur "Theme/docroot/WEB-INF" folder

code :-
                 <theme id="Your-Theme-Id" name="Your Theme Name">
       <settings>
            <setting key="portlet-setup-show-borders-default" value="false" />
        </settings>
    </theme>

Role checking in Template/vm file , Liferay

To perform the accesing of the service layers in web content we need to add the propertie in the portal-ext.properties file

journal.template.velocity.restricted.variables=

#set($roleLocalServiceUtil = $serviceLocator.findService("com.liferay.portal.service.RoleLocalService"))
#set($adminrole = $roleLocalServiceUtil.getRole($company_id, "Administrator"))

#set($hasadminrole = $roleLocalServiceUtil.hasUserRole($user_id, $getterUtil.getLong($adminrole.getRoleId())))

How to Identify that SignedIn User is having particualr Role or Not in Liferay

Here i am writing example code which is used to check that the signedIn User is having the Administrator Role or Not

<%@page import="com.liferay.portal.model.Role"% ><%@page import="com.liferay.portal.service.RoleLocalServiceUtil"%>
      long companyId = themeDisplay.getCompanyId();
       Role roleAdmin = RoleLocalServiceUtil.getRole(companyId, "Administrator");
    
      if(RoleLocalServiceUtil.hasUserRole(themeDisplay.getUserId(), roleAdmin.getRoleId())) {

       }

The Above Code is to check that the SignedIn User is having 'Administrator'  Role or Not

Thursday, December 20, 2012

Toggle / Collapse and Expand using JQuery

 <script src="http://code.jquery.com/jquery-1.8.2.min.js" >  </script>

<script type="text/javascript">
    jQuery('#clickme').click(function() {     //this line is for to work onclick functionality
    jQuery('#content').toggle();                  // thsi line is for toggle option
    jQuery('#minus').toggleClass('minus');  //this line is for plus and minus image
});
</script>

<div id="clickme"> <a href="javascript:void(0);"> Click Me </a> </div>
<div id="content">
<p>
        This content will be collapse and expanded
</p>
<p>
      For plus and minus symbols u need to apply css
</p>
</div>

Note : For any clarification just post a comment 

Tuesday, October 30, 2012

How To Customize the Default Text Editor of Liferay in Custom Portlet

Ever wanted to use a rich text editor (RTE) such as the CK Editor in your custom portlet?
Implementing an RTE in your view is (almost) as simple as using a jsp-tag:

<aui:field-wrapper label="description">
    <liferay-ui:input-editor name="descriptionEditor" toolbarSet="liferay-article" initMethod="initEditor" width="200" />
    <script type="text/javascript">
        function <portlet:namespace />initEditor() { return "<%= UnicodeFormatter.toString("default content") %>"; }
    </script>
</aui:field-wrapper>


The liferay-ui:input-editor tag does not have a label attribute. To include a label for the RTE, wrap the tag in a aui:field-wrapper tag as shown above.
Also, the liferay-ui:input-editor needs an initMethod defined in javascript that sets the initial value of the RTE. In my example above, the RTE will be initialized with the value "default content". In your own view, obviously you would want to exchange "default value" for a bean value.

Editor toolbar

Now, the code above works great and will provide you with a toolbar (the set of actions/operations in the editor) that looks like the one used when editing wcm-articles.
Liferay comes with four different predefined toolbar sets:
  • liferay
  • liferay-article
  • email
  • edit-in-place
Each toolbar sports its own set of actions/operations. The most slimmed one being the email toolbar set.
The toolbar sets are defined in a file called ckconfig.jsp which you'll find in /webapps/ROOT/html/js/editor/ckeditor/ in your Liferay bundle.

Changing a predefined toolbar

The toolbar set called "liferay-article" is defined in ckconfig.jsp like this:
CKEDITOR.config.toolbar_liferayArticle = [
    ['Styles', 'FontSize', '-', 'TextColor', 'BGColor'],
    ['Bold', 'Italic', 'Underline', 'Strike'],
    ['Subscript', 'Superscript'],
    '/',
    ['Undo', 'Redo', '-', 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'SelectAll', 'RemoveFormat'],
    ['Find', 'Replace', 'SpellChecker', 'Scayt'],
    ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
    ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'],
    '/',
    ['Source'],
    ['Link', 'Unlink', 'Anchor'],
    ['Image', 'Flash', 'Table', '-', 'Smiley', 'SpecialChar', 'LiferayPageBreak']
];

Thus, if we would like to remove the option for TextColor, we would need to remove this entry in the definition. This can be done by replacing the ckconfig.jsp file with a custom-jsp hook. If you don't know how to implement a custom jsp hook, you can check this wiki page.

Adding a new toolbar

Similar to the procedure above, you may add a new custom toolbar by adding a toolbar definition to the ckconfig.jsp file with a custom-jsp hook. Let's create one called "slimmed" that is just a simple editor with the option to make text bold, italic and underline. Also let's add the option to insert links:
CKEDITOR.config.toolbar_slimmed = [
    ['Bold', 'Italic', 'Underline'],
    ['Link', 'Unlink']
];

Deploy your custom jsp hook. Now change your liferay-ui:input-editor to use the slimmed toolbar set:
<aui:field-wrapper label="description">
    <liferay-ui:input-editor name="descriptionEditor" toolbarSet="slimmed" initMethod="initEditor" width="200" />
    <script type="text/javascript">
        function <portlet:namespace />initEditor() { return "<%= UnicodeFormatter.toString("default content") %>"; }
    </script>
</aui:field-wrapper>

Monday, October 29, 2012

How to overcome " float:right" issue in IE7 ( css issue )

This Issue is common that ," float : right " will not work in IE7 ,to overcome that we can use as follows

Example :
.css :

.float-right  {
     float : right;

}

.ie7 .float-right {
    position : absolute;
   right : 15px;
}




Removing Dotted line to Anchore Tag or <a> in IE

This is one of the Big Issue ,that IE browser will display the "Dotted Line " ,when you "hover","visited" and "active".

 .css

a , a:hover , a:visited , a:active {
         border:none;
         outline:none;
}

Thursday, October 18, 2012

Display * rather than Required label in AUI form

You need the get the label value from the " Language.properties " file rather than giving direct value in the " label " attribute in the AUI input tag.

example:-

Language.Properties : -

first-name-req = First Name <em class="star"> * <em>

email-req = Email Id <em class="star"> * <em>

phone-req = Mobile Number <em class="star"> * <em>

.jsp page :-

<aui:form name="fm" method="POST" action="<%=customerURL%>" inlineLabels="true">


<aui:input name="firstName" label="first-name-req" value='<%= %>' autocomplete="off">
<aui:validator name="required" />
<aui:validator name="minLength" errorMessage="Firs Name can not be less than 5 characters. Please try again" >5</aui:validator>
<aui:validator name="maxLength" errorMessage="First Name is too long. Please try again" >75</aui:validator>
</aui:input>

<aui:input name="emailId" label="email-req" value='<%= %>' autocomplete="off">
<aui:validator name="required" />
<aui:validator name="alphaNumeric" />
<aui:validator name="maxLength" errorMessage="First Name is too long. Please try again" >256</aui:validator>
</aui:input>

<aui:input name="phoneNo" label="phone-req" value='<%= %>' autocomplete="off">
<aui:validator name="required" />
<aui:validator name="number" />
<aui:validator name="minLength" errorMessage="First Name is too long. Please try again" >10</aui:validator>
</aui:input>

</aui:form>

css :-
.star {
   color : red ;
}

.aui-label-required {
 display : none;
}




Wednesday, September 26, 2012

Import or Export " .sql " or ".csv" file in/from mysql

Importing .sql  file into mysql database

1.Go to mysql command prompt.
2.Go to the database , in which you want to import a .sql file.
3.Then use the following command to import file.

          " source path-of-the-sqlfile  "

Note:  Source is the keyword  after that u have to give the path of the file where that sql file is present

Exporting a file from mysql database

1.Go to windows command prompt ( mysql path must be set in the environment variables )
2.Then use the following command to import file.

      " mysqldump -u username -ppassword databasename tablename  > filename.sql "
                                   
                                                        OR

     mysqldump -u username -ppassword databasename tablename  > give-path-where-u-want-to-store-the-sql-file/filename.sql"

Importing .csv file into mysql database

load data local infile 'E:/Sample/sample.csv' into table fing_myresult fields terminated by ',' enclosed by '"' lines terminated by '\n' (columnName1,columnName2,columnName3,columnName4)

Wednesday, August 29, 2012

Removing Portlet Dynamically If It Is Empty in Liferay


 To remove portlet from Page when portlet is empty.

renderRequest.setAttribute(WebKeys.PORTLET_CONFIGURATOR_VISIBILITY, Boolean.FALSE)

Wednesday, August 22, 2012

Playing video in popup using jQuery

Window with playing video   
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Window with playing video    </title>
<style type="text/css">
a {     text-decoration:none; 
    color:red;
}
.container {width: 960px; margin: 0 auto; overflow: hidden;}
#content {    float: left; width: 100%;}
#mask {
    display: none;
    background: #000; 
    position: fixed; left: 0; top: 0; 
    z-index: 10;
    width: 100%; height: 100%;
    opacity: 0.8;
    z-index: 999;
}
.login-popup{
    display:none;
    background: #333;
    padding: 10px;    
    border: 2px solid #ddd;
    float: left;
    font-size: 1.2em;
    position: fixed;
    top: 50%; left: 50%;
    z-index: 99999;
    box-shadow: 0px 0px 20px #999;
    -moz-box-shadow: 0px 0px 20px #999; /* Firefox */
    -webkit-box-shadow: 0px 0px 20px #999; /* Safari, Chrome */
    border-radius:3px 3px 3px 3px;
    -moz-border-radius: 3px; /* Firefox */
    -webkit-border-radius: 3px; /* Safari, Chrome */
}
img.btn_close {
    float: right; 
    margin: -28px -28px 0 0;
}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    $('a.login-window').click(function() {
        // Getting the variable's value from a link 
        var loginBox = $(this).attr('href');
        //Fade in the Popup and add close button
        $(loginBox).fadeIn(300);
        //Set the center alignment padding + border
        var popMargTop = ($(loginBox).height() + 24) / 2; 
        var popMargLeft = ($(loginBox).width() + 24) / 2; 
        $(loginBox).css({ 
            'margin-top' : -popMargTop,
            'margin-left' : -popMargLeft
        });
        // Add the mask to body
        $('body').append('<div id="mask"></div>');
        $('#mask').fadeIn(300);
        return false; <!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Window with playing video    </title>
<style type="text/css">
a {     text-decoration:none; 
    color:red;
}
.container {width: 960px; margin: 0 auto; overflow: hidden;}
#content {    float: left; width: 100%;}
#mask {
    display: none;
    background: #000; 
    position: fixed; left: 0; top: 0; 
    z-index: 10;
    width: 100%; height: 100%;
    opacity: 0.8;
    z-index: 999;
}
.login-popup{
    display:none;
    background: #333;
    padding: 10px;    
    border: 2px solid #ddd;
    float: left;
    font-size: 1.2em;
    position: fixed;
    top: 50%; left: 50%;
    z-index: 99999;
    box-shadow: 0px 0px 20px #999;
    -moz-box-shadow: 0px 0px 20px #999; /* Firefox */
    -webkit-box-shadow: 0px 0px 20px #999; /* Safari, Chrome */
    border-radius:3px 3px 3px 3px;
    -moz-border-radius: 3px; /* Firefox */
    -webkit-border-radius: 3px; /* Safari, Chrome */
}
img.btn_close {
    float: right; 
    margin: -28px -28px 0 0;
}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    $('a.login-window').click(function() {
        // Getting the variable's value from a link 
        var loginBox = $(this).attr('href');
        //Fade in the Popup and add close button
        $(loginBox).fadeIn(300);
        //Set the center alignment padding + border
        var popMargTop = ($(loginBox).height() + 24) / 2; 
        var popMargLeft = ($(loginBox).width() + 24) / 2; 
        $(loginBox).css({ 
            'margin-top' : -popMargTop,
            'margin-left' : -popMargLeft
        });
        // Add the mask to body
        $('body').append('<div id="mask"></div>');
        $('#mask').fadeIn(300);
        return false;
    });
    // When clicking on the button close or the mask layer the popup closed
    $('a.close, #mask').live('click', function() { 
      $('#mask , .login-popup').fadeOut(300 , function() {
        $('#mask').remove();  
    }); 
    return false;
    });
});
</script>

</head>
<body>
<div class="container">
    <div id="content">
        <a href="#login-box" class="login-window">Login / Sign In</a>
        <div id="login-box" class="login-popup">
        <a href="#" class="close">
            <span class="btn_close">CLOSE</span>
        </a>
    <p>
        <iframe allowfullscreen="" frameborder="0" height="237" src="http://www.youtube.com/v/iJuOs_Gjcow?fs=1&hl=en_US&rel=0&autoplay=1"             width="350" allowscriptaccess="always"></iframe>
    </p>
        </div>
    
    </div>
</div>
</body>
</html>
    });
    // When clicking on the button close or the mask layer the popup closed
    $('a.close, #mask').live('click', function() { 
      $('#mask , .login-popup').fadeOut(300 , function() {
        $('#mask').remove();  
    }); 
    return false;
    });
});
</script>

</head>
<body>
<div class="container">
    <div id="content">
        <a href="#login-box" class="login-window">Login / Sign In</a>
        <div id="login-box" class="login-popup">
        <a href="#" class="close">
            <span class="btn_close">CLOSE</span>
        </a>
    <p>
        <iframe allowfullscreen="" frameborder="0" height="237" src="http://www.youtube.com/v/iJuOs_Gjcow?fs=1&hl=en_US&rel=0&autoplay=1"             width="350" allowscriptaccess="always"></iframe>
    </p>
        </div>
    
    </div>
</div>
</body>
</html>
   

Tuesday, August 7, 2012

Loading mask using AUI/alloy UI

//to Enable the Loading mask write this code in starting of your task
AUI().use( 'aui-loading-mask', function(A){
                         if (A.one('#tagid').loadingmask == null)
                        A.one('#tagid').plug(A.LoadingMask, { background: '#000' });
                            A.one('#tagid').loadingmask.toggle();
                });

//to Disable the loading mask once again call the toggle(); , write this after compleation of your task

AUI().use( 'aui-loading-mask', function(A){
            A.one('#tagid').loadingmask.toggle();
      });

Note : Here #tagid is id of the tag where you want to display loading mask

Sunday, August 5, 2012

How to Load image from theme to Template in Liferay


#set ($Image_path = $request.get("theme-display").get("path-theme-images"))

<img src= "$Image_path/foldername/imagename"/>
 
Note : foldername - if you have any folder in images folder with in
       the '_diffs' folder of your theme then it is required.
 
       imagename - Name of your image ex welcome.png etc.
 
Another way :-
 
<img src= "${themeDisplay.pathThemeImages}/foldername/imagename"/> 
 
 

Thursday, July 26, 2012

How to overcome jQuery conflict

 The below code is used to overcome the jQuery conflict

   <script src='jquery-1.3.2.js' > </script>

   
<script>    var jq132 = jQuery.noConflict();     </script>

    
<script src='jquery-1.4.2.js'> </script>

  
<script>var jq142 = jQuery.noConflict();   </script> 

Thursday, July 12, 2012

To Store External JAR file into a local Repository of Maven

To store External JAR into your Local Repository of Maven .

1. First you need to modify the " settings.xml " which is present with in the " conf  " folder of maven installed folder .

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd" >
localRepository
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ~/.m2/repository


  < localRepository>  /opt/apache-maven-3.0.4/repositoryfolder </localRepository> 


You need to create " repositoryfolder " inside the maven installed folder .

NOTE : if you are creating a folder in Linux OS then you need to change the permissions to that folder , you need to change the ownership to the current user .

        ex :  chown username : username repositoryfolder                                      

If the first step is already done then you can continue from the second step.

2. To use the External JAR's ,the External JAR's must be placed in the local repository in the correct place in order for it to be correctly picked up by Maven. To make this easier, and less error prone, we have provide a goal in the install plug-in which should make this relatively painless. 

To install a External JAR in the local repository use the following command :

 ex  :  mvn install:install-file -Dfile=d:\myfolder\myjar.jar 
 -DgroupId=com.mygroup -DartifactId=myjar -Dversion=1.0.0  
-Dpackaging=jar

After doing this it will be use to download the External JAR file into your local Repository .

3. Modify the pom.xml file 
    
After doing the above steps you need to modify the " pom.xml " file like this

ex :
<dependency>
  <groupId>com.mygroup</groupId>
 <artifactId>myjar</artifactId>
 <version>1.0.0</version>
  </dependency

Thursday, April 12, 2012

Set the Portlet Title at RunTime in Liferay

RENDERRESPONSE.SETTITLE(LANGUAGEUTIL.GET(RENDERREQUEST.GETLOCALE(), "WELCOME", "WELCOME"));

The above line is used to set the title of portlet at runtime ,this is example for the welcome portlet

Liferay DXP JNDI Data Source Cofiguration

 This Blog will help us to learn about the JNDI Data Source Configuration in Liferay DXP. We have tested this with Liferay 7.3 with Tomcat. ...