Fórumok

Portlet reading from a custom properties file

Øyvind Askedal, módosítva 11 év-val korábban

Portlet reading from a custom properties file

New Member Bejegyzések: 2 Csatlakozás dátuma: 2012.05.21. Legújabb bejegyzések
Hi,

I'm new in Liferay and I'm trying to create a portlet that reads menu items from a properties file, as the menu items are most likely going to be all static datas. The portlet should then be integrated at the bottom in my theme. Any good tutorials or links on where to start?
My first guess was this, but I only get the message
\WEB-INF\classes\bottomMenu.properties (The system cannot find the path specified)

so I guess this is not the way?

Here is my code in the doView method of my portlet:

public void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException {
		
		Properties properties = new Properties();
		String value="";
		try {
			String url = "/WEB-INF/classes/bottomMenu.properties";
			properties.load(new FileInputStream(url));
			
			for(String key : properties.stringPropertyNames()) {
				value = properties.getProperty(key);
				System.out.println(key + "=>" + value);
			}
			
			renderRequest.setAttribute("url",value);
			
		
		} catch (IOException e1) {
			
			System.out.println(e1);
			
		}
		
		//this.include(this.viewJSP, renderRequest, renderResponse);
		super.doView(renderRequest, renderResponse);
		
	}
thumbnail
Vilmos Papp, módosítva 11 év-val korábban

RE: Portlet reading from a custom properties file

Liferay Master Bejegyzések: 529 Csatlakozás dátuma: 2010.10.21. Legújabb bejegyzések
Hi,

Please check the Mail Portlet, there you can see how to use portlet.properties for portlet specific property settings.

Regards,
Vilmos
thumbnail
Samuel Kong, módosítva 11 év-val korábban

RE: Portlet reading from a custom properties file

Liferay Legend Bejegyzések: 1902 Csatlakozás dátuma: 2008.03.10. Legújabb bejegyzések
Probably a class loader issue. To avoid dealing with the class loader issue, just name your properties file, portlet.properties and place the file at /docroot/WEB-INF/src/portlet.properties Then you can just use the below code tor read your properties file:

String value = com.liferay.util.portlet.PortletProps.get("my.property.key");
thumbnail
Hitoshi Ozawa, módosítva 11 év-val korábban

RE: Portlet reading from a custom properties file

Liferay Legend Bejegyzések: 7942 Csatlakozás dátuma: 2010.03.24. Legújabb bejegyzések
Following page contains a sample:

http://www.liferay.com/community/wiki/-/wiki/Main/How+to+add+a+Properties+File+to+a+Portlet
Ram A, módosítva 11 év-val korábban

RE: Portlet reading from a custom properties file

Junior Member Bejegyzések: 76 Csatlakozás dátuma: 2013.01.16. Legújabb bejegyzések
Hi ,

Can anyone help me how to read the pom.properties file inside my portlets.
path : target\maven-archiver\pom.properties.

i think i have to read it as reading a file from classpath.



Thanks in advance
Ram A
thumbnail
David H Nebinger, módosítva 11 év-val korábban

RE: Portlet reading from a custom properties file

Liferay Legend Bejegyzések: 14919 Csatlakozás dátuma: 2006.09.02. Legújabb bejegyzések
ClassLoader.getResourceAsStream("target/maven-archiver/pom.properties") to get the input stream. Route to a new Properties instance (has loading from input stream), where you can fetch the property.
K. Behrends, módosítva 9 év-val korábban

RE: Portlet reading from a custom properties file

New Member Bejegyzések: 4 Csatlakozás dátuma: 2012.01.06. Legújabb bejegyzések
You can read the base.path property to get the path to the portlet.properties file, and then work your way to your custom file.

Properties props = loadProperties(); //liferay API


String basepath = props.getProperty("base.path");
Properties customprops = readPropfile(basepath);


and then

public Properties readPropfile(String defaultpropfilename){

Properties props = new Properties();
InputStream is = null;
File file = new File(defaultpropfilename);
String parentDirName = file.getParent();

// try loading from the same directory
try {
File f = new File(parentDirName, "bottomMenu.properties");
is = new FileInputStream( f );
props.load( is );
is.close();
}
catch ( Exception e ) { is = null;
e.printStackTrace();

}

return props;

}
thumbnail
Tariqul Islam, módosítva 9 év-val korábban

RE: Portlet reading from a custom properties file

New Member Bejegyzések: 15 Csatlakozás dátuma: 2013.01.27. Legújabb bejegyzések