Site icon Pro Liferay

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”);

Exit mobile version