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 thoughts on “How To”

  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.

    1. You can create some dummy web content and place it in your page where your theme is enabled. Check the look and feel that you want. Accordingly you can modify the theme to get required look and feel.

      Regards
      Admin
      https://www.proliferay.com

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

  3. 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.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top