FAQ

Q.I want to add jsp page in my theme. But how?
Ans:
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")

Q. I want to read properties file in my portlet. 
Ans:
 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 comments:

  1. hi..
    i am getting some error in starting tomcat server


    log4j:ERROR LogMananger.repositorySelector was null likely due to error in class reloading, using NOPLoggerRepository.

    please help me with this...

    ReplyDelete
  2. after replacing log4j..now its coming...



    Loading jar:file:/D:/liferay/liferay-portal-tomcat-6.0.6-20110225/liferay-portal-6.0.6/tomcat-6.0.29/webapps/ROOT/WEB-INF/lib/portal-impl.jar!/portal.properties

    just loading....

    ReplyDelete
  3. in console..its still loading shows..and server has started..but i am not open the site..404 error

    ReplyDelete
  4. Check that your database server is up or not?

    ReplyDelete
  5. assalamu alaikum.. i want to start my own freelancing web devlopement work .please tell me how can i start please send me the whole detail
    thanks

    ReplyDelete
  6. Thanks for the post, I am techno savvy. I believe you hit the nail right on the head. I am highly impressed with your blog.
    It is very nicely explained. Your article adds best knowledge to our Java Online Training from India.
    or learn thru Java Online Training from India Students.

    ReplyDelete