How To

1.  How to configure database in Liferay?

Answer:-

Liferay database configuration is done in portal-ext.properties. In Liferay tomcat bundle the location of this file is tomcat-7.0.42\webapps\ROOT\WEB-INF\classes

If the file is not there then you can create it. For MySQL database configuration put the below code in portal-ext.properties file.

    jdbc.default.driverClassName=com.mysql.jdbc.Driver
    jdbc.default.url=jdbc:mysql://localhost/lportal620?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
    jdbc.default.username=root
    jdbc.default.password=

In the above

lportal620 is the database Name
root is the User Name
jdbc.default.password= Is the password which is empty. Consider your password is sa then it should be
jdbc.default.password=sa
jdbc:mysql://localhost/lportal620 is the database URL


 

2.  How to add JSP page in theme?

Answer:-

Create the jsp page under the "docroot" folder of your theme. Say you have created /jsp/view.jsp under your docroot folder then you can include the view.jsp in any one of vm file as follows

     $theme.include($themeServletContext, "/jsp/view.jsp")

 


3.  How to read properties file in portlet?

Answer:-

There are 2 ways you can read properties file in liferay portlet.
A) Just create portlet.properties under src folder of your portlet and write some key value inside your portlet.properties file. You can read the key as bellow...

    String value = PortletProps.get("key");

B) You can load your own properties file with your custom name file. Create a class with the following  name


import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class PropsUtil {
   
    private static Properties props = null;
   
    private  PropsUtil(){
        ClassLoader classLoader = getClass().getClassLoader();
        InputStream is = classLoader.getResourceAsStream("resource/sample.properties");
        props = new Properties();
        try {
            props.load(is);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
   
    private static synchronized Properties getProperty(){
        if(props == null){
            new PropsUtil();
            return PropsUtil.props;
        }else{
            return props;
        }
    }
   
    public static String get(String key){
       
        return getProperty().getProperty(key);
    }
}

Here resource/sample.properties is your properties file that's under src\resource folder. You can get the key value as bellow
String value = PropsUtil.get("key");

7 Responses so far.

  1. Hi,

    I am creating a theme for LR 6.2 and now I want dummy or sample content to check whether my theme is working properly or not.

    Do you have any idea? I don't want to force user to create web content or portlet for theme testing only.

  2. Mahesh says:

    Realy its a good article..You have clarified so many things which i have been searching...good job...

  3. Alok Halder says:

    This is good site

  4. vamsi alla says:

    This is good site

  5. raghu says:

    Hamidul- Your articles are good read. kudos!.
    I was looking to import header and footer from an existing web page. Is it possible to do this without loosing the functionality of the existing page. Is Velocity required in this case.
    Thanks.

  6. Mahesh says:

    HI Hamidul,
    Can you post an article how to create login.jsp hook in liferay7?

Leave a Reply

Your email address will not be published. Required fields are marked *

Are you human? * Time limit is exhausted. Please reload CAPTCHA.

Top
%d bloggers like this:

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close