フォーラム

ホーム » Liferay Portal » English » x. Miscellaneous

構造的に表示 平面上に表示 ツリー上に表示
スレッド [ 前へ | 次へ ]
toggle
Øyvind Askedal
Portlet reading from a custom properties file
2012/08/15 0:41
答え

Øyvind Askedal

ランク: New Member

投稿: 2

参加年月日: 2012/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:

 1public void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException {
 2       
 3        Properties properties = new Properties();
 4        String value="";
 5        try {
 6            String url = "/WEB-INF/classes/bottomMenu.properties";
 7            properties.load(new FileInputStream(url));
 8            
 9            for(String key : properties.stringPropertyNames()) {
10                value = properties.getProperty(key);
11                System.out.println(key + "=>" + value);
12            }
13            
14            renderRequest.setAttribute("url",value);
15            
16       
17        } catch (IOException e1) {
18            
19            System.out.println(e1);
20            
21        }
22       
23        //this.include(this.viewJSP, renderRequest, renderResponse);
24        super.doView(renderRequest, renderResponse);
25       
26    }
Vilmos Papp
RE: Portlet reading from a custom properties file
2012/08/15 2:41
答え

Vilmos Papp

LIFERAY STAFF

ランク: Expert

投稿: 425

参加年月日: 2010/10/21

最近の投稿

Hi,

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

Regards,
Vilmos
Samuel Kong
RE: Portlet reading from a custom properties file
2012/08/15 2:51
答え

Samuel Kong

LIFERAY STAFF

ランク: Liferay Master

投稿: 935

参加年月日: 2008/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:

1String value = com.liferay.util.portlet.PortletProps.get("my.property.key");
Hitoshi Ozawa
RE: Portlet reading from a custom properties file
2012/08/15 4:18
答え

Hitoshi Ozawa

ランク: Liferay Legend

投稿: 7990

参加年月日: 2010/03/23

最近の投稿

Following page contains a sample:

http://www.liferay.com/community/wiki/-/wiki/Main/How+to+add+a+Properties+File+to+a+Portlet
Ram A
RE: Portlet reading from a custom properties file
2013/01/30 7:36
答え

Ram A

ランク: Junior Member

投稿: 76

参加年月日: 2013/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
David H Nebinger
RE: Portlet reading from a custom properties file
2013/01/30 10:56
答え

David H Nebinger

ランク: Liferay Legend

投稿: 6275

参加年月日: 2006/09/01

最近の投稿

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.