LoginSignup
2

More than 3 years have passed since last update.

JSFのHtml5Friendlyチートシート

Posted at

JSFタグでも動くには動くのですが、混在しているのはあまり良くないらしいのでHTML5に寄せてコーディングしていきます。
基本的にHtml5Friendly寄せです。
前提条件はJavaEE7でJSF2.2

h:messages

<span jsfc="h:messages" class="error_style" />

h:commandButton

<button jsf:action="#{bean.action}">
  次へ
  <f:param name="id" value="#{bean.id}" />
</button>

h:button

<button jsf:outcome="next_page?id=#{bean.id}&amp;faces-redirect=true">
  次へ
</button>

// おまけ:サーブレットにGETアクセスさせる
<button onClick="window.location.href='login/service?id=#{bean.param1}&amp;status=#{bean.param2}'">
  ログイン
</button>

h:inputText

<input jsf:id="name" type="text" jsf:value="#{bean.name}" />

h:selectOneRadio

ラジオボタンやチェックボタンだけはまだJSFタグの方が推奨されるみたいです(2018年2月時点)

<h:selectOneRadio id="selectPrize" name="prizeName" value="#{entryFieldBean.prizeName}" styleClass="radio_list">
  <f:selectItems value="#{entryFieldBean.prizeList}" var="prize" itemLabel="#{prize.labelName}" itemValue="#{prize}" />
</h:selectOneRadio>

rendered属性

// 一致
<div class="sample" jsf:rendered="#{bean.str == ''}">
</div>
// 不一致
<div class="sample" jsf:rendered="#{bean.str != ''}">
</div>
// nullと一致
<div class="sample" jsf:rendered="#{bean.str == null}">
</div>
// beanの変数で判定
<div class="sample" jsf:rendered="#{bean.isStatus}">
</div>
// andで複数条件
<div class="sample" jsf:rendered="#{bean.str == '' and bean.isStatus}">
</div>
// orで複数条件
<div class="sample" jsf:rendered="#{bean.str == '' or bean.isStatus}">
</div>

ui:remove

コメントアウトはui:remove
通常のHTMLのコメントタグ<!-- -->だとJSFのタグは無効になりません。
文字コメントのみでもレンダリングに影響するっぽい(クラスタリング環境だけ?)ので基本コメントは書かないかui:removeで囲った方が安全です。
またweb.xmlにjavax.faces.FACELETS_SKIP_COMMENTSという設定項目がありますがui:removeの方が優先されるっぽいです。

<ui:remove>
    <!-- ※ライブラリの注意点とかメモ書き※ -->
</ui:remove>

h:outputStylesheet

<link rel="stylesheet" type="text/css"
          href="#{bean.resourcesPath}/css/style.css" media="all" />

h:outputScript

  <script type="text/javascript" src="#{bean.resourcesPath}/js/common.js" />

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2