xmlliferayportletliferay-6init-parameters

how to get init param of portlet.xml in liferay?


i am using custom porltet in my liferay portal 6.i have some global variable that i want to use through out my portlet classes so for that i have written that variable in portlet.xml file as follows..

<init-param>
        <name>Host</name>
        <value>smtp.mail.yahoo.com</value>
</init-param>

<init-param>
        <name>Port</name>
        <value>465</value>
</init-param>

function which working perfect in my portlet action class

publicList<String> ReadSmtpDataForMailNotification() {

        List<String> ValuesListObj = new ArrayList<String>();
        ValuesListObj.add(this.getInitParameter("Host"));
        ValuesListObj.add(this.getInitParameter("Port"));
        return ValuesListObj;
    }

now problem is that when i excute the function withing the portlet action class then its working perfect but when i want to access this variable outside my portlet class..e.g :- in my local service impl class then i cant access that varible and the value come is always null..so please if anyone can suggest me how can i do get the value of initparam in other then portlet class.

@Advaita Gosvami

have written my.custom.host=liferay.css.com in portlet.properties file

and when i try to fetch value with the following

 System.out.println("Property value : - " + PropsUtil.get("my.custom.host"));

its giving me null value..


Solution

  • Anyways I Have Done like this as @Advaita Gosvami told before with the changes in portlet.properties but some how it doesnt work with my custom key...

    mail.session.mail.smtps.auth=true
    mail.session.mail.smtps.host=smtp.gmail.com
    mail­.session.mail.smtps.password=***********(your password here)
    mail.session.mail.smtps.port=465
    mail.session.mail.s­mtps.user=liferay.test@gmail.com(your emailId Here)
    mail.session.mail.transport.protocol=smtp
    

    and i am calling it with

    PortletProps.get("mail.session.mail.smtps.host");
    

    its gave me perfect value from anywhere i call in my custom portlet

    Thanx @Advaita Gosvami for your valueble help.just in case u decalre custom key in portlet properties givng me null value.but with this keys as i have mentioned above in portlet properties i can access...thnx a lot