開発者ドキュメント

JSF 2.0テンプレートファイルにパラメータを渡すには?

JSF 2.0 Webアプリケーションでは、 ”

ui:param

” faceletsタグを使用して、インクルードファイルまたはテンプレートファイルにパラメータを渡すことができます。

1. “ui:include”のパラメータ

“tagLine”パラメータをインクルードファイルに渡す例

<ui:insert name="header" >
   <ui:include src="/template/common/commonHeader.xhtml">

    <ui:param name="tagLine" value="JSF a day, bug away"/>

   </ui:include>
</ui:insert>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      >
    <body>
        <ui:composition>
        <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle"
     style="display:block; text-align:center;"
     data-ad-format="fluid"
     data-ad-layout="in-article"
     data-ad-client="ca-pub-2836379775501347"
     data-ad-slot="6894224149"></ins>
<script>
     (adsbygoogle = window.adsbygoogle ||[]).push({});
</script><h2>Tag Line : #{tagLine}</h2>
    </ui:composition>
    </body>
</html>

2. “ui:composition”のパラメータ

“curFileName”パラメータをテンプレートファイルに渡す例

<ui:composition template="template/common/commonLayout.xhtml">

    <ui:param name="curFileName" value="default.xhtml"/>

</ui:composition>
  • commonLayout.xhtml ** ファイルでは、通常のEL式で “curFileName”パラメータにアクセスできます。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      >
    <h:body>

    <div id="content">
            Current File : #{curFileName}
    </div>

    </h:body>
</html>

ソースコードをダウンロードする

ダウンロードする – リンク://wp-content/uploads/2010/10/JSF-2-Parameter-In-Template-Example.zip[JSF-2-パラメータ – インテンプレート – サンプル.zip](12KB)

モバイルバージョンを終了