刘政道 - 应用程序框架

《31天学会CRM项目开发(C#编程入门及项目实战)》作者,IT经理,程序员
  博客园  :: 新随笔  :: 联系 :: 管理

在JSF中使用*.properties资源文件

Posted on 2009-06-09 16:25  刘政道  阅读(570)  评论(0编辑  收藏  举报

转载:http://ceapet.com/blog/index.php?option=com_content&view=article&id=204:jsfproperties&catid=38:java&Itemid=64


p.properties文件内容如下
name=ceapet
description=Ceapet online exam system!

在.jsf文件中如下调用
#{main.p.name}
#{main.p.description}


创建一个类,便于加载 p.properties
import java.io.*;
import java.util.Properties;

public class main
{
    public static Properties p;
    public main()
    {
        if(this.p == null)
        {
            try
            {
                String filename = "../webapps/*/p.properties";
                File f = new File(filename);
                if(f.exists())
                {
                    InputStream is = new FileInputStream(filename);
                    p = new Properties();
                    p.load(is);
                    is.close();
                }
                else
                {
                    System.out.print(filename + "不存在");
                }
                f = null;
            }catch(Exception ex){System.out.print(ex.getMessage());}
        }
    }
    public Properties getP()
    {
        return this.p;
    }

}

这是一个比较管用的方法。但是,我一直还不知道jbpm-console中的#{msgs['name']}是如何实现的。至今我还不知该怎样在JSF中 想方法传递参数。