从JSF中的属性文件访问变量



我的项目中有属性文件,我放置了所有URL和其他配置属性。

我有一个我想在.xhtml页面中使用的URL。我尝试了很多事情,但没有成功。

下面是我的JSF页面:

<ui:composition template="/WEB-INF/templates/mainlayout.xhtml"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:f="http://xmlns.jcp.org/jsf/core"
                xmlns:h="http://xmlns.jcp.org/jsf/html"
                xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
                xmlns:a="http://xmlns.jcp.org/jsf/passthrough"
                xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
                xmlns:p="http://primefaces.org/ui"
                xmlns:pe="http://primefaces.org/ui/extensions">
  <ui:define name="content">
    <div id="iFrameContainer">
        <iframe  width="100%" 
                 height="100%" 
                 frameborder="0" 
                 src="http://testURL">
        </iframe>
    </div>
  </ui:define>
</ui:composition>

testURL是我要使用属性文件URL参数的地方。

在您的 faces-config.xml add:

<resource-bundle>
  <base-name>package.name_of_properties_file</base-name>
  <var>props</var>
</resource-bundle>  

然后,在facelets文件中您可以使用它:

 <div id="iFrameContainer">
    <iframe  width="100%" 
             height="100%" 
             frameborder="0" 
             src="#{props['textUrl']}"
             >
    </iframe>
</div>

最新更新