掲示板

Portlet reading from a custom properties file

11年前 に Øyvind Askedal によって更新されました。

Portlet reading from a custom properties file

New Member 投稿: 2 参加年月日: 12/05/21 最新の投稿
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
11年前 に Vilmos Papp によって更新されました。

RE: Portlet reading from a custom properties file

Liferay Master 投稿: 529 参加年月日: 10/10/21 最新の投稿
Hi,

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

Regards,
Vilmos
thumbnail
11年前 に Samuel Kong によって更新されました。

RE: Portlet reading from a custom properties file

Liferay Legend 投稿: 1902 参加年月日: 08/03/10 最新の投稿
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
11年前 に Hitoshi Ozawa によって更新されました。

RE: Portlet reading from a custom properties file

Liferay Legend 投稿: 7942 参加年月日: 10/03/24 最新の投稿
Following page contains a sample:

http://www.liferay.com/community/wiki/-/wiki/Main/How+to+add+a+Properties+File+to+a+Portlet
11年前 に Ram A によって更新されました。

RE: Portlet reading from a custom properties file

Junior Member 投稿: 76 参加年月日: 13/01/16 最新の投稿
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
11年前 に David H Nebinger によって更新されました。

RE: Portlet reading from a custom properties file

Liferay Legend 投稿: 14916 参加年月日: 06/09/02 最新の投稿
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.
9年前 に K. Behrends によって更新されました。

RE: Portlet reading from a custom properties file

New Member 投稿: 4 参加年月日: 12/01/06 最新の投稿
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
9年前 に Tariqul Islam によって更新されました。

RE: Portlet reading from a custom properties file

New Member 投稿: 15 参加年月日: 13/01/27 最新の投稿