0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【JSF】画面の状態によってタグを出し分けしたい

Posted at

やりたいこと

入力値によってタグの表示非表示を出し分けしたい。

ex.(formに値が入っている場合は普通のボタンを、入っていない場合は非活性のボタンを表示させたい

どうやる?

  • JSFのタグはrenderd属性を指定することで表示、非表示の制御ができる。
    • renderedがfalseになっているものはタグ自体がレンダリングされない。
  • レンダリングされていないタグを、ajaxで更新することはできない。
    • renderがfalseのタグは更新不可

じゃあ初期値を非表示にしているタグをレンダリングできないの?
→常に表示される親タグに対して更新を行うことで可能

参考 : jsf – Ajaxの更新/レンダリングは、属性がレンダリングされたコンポーネントでは機能しません - コードログ

実装例

特定のフラグによってaタグの挙動を変える

  • フラグがtrue: モーダル表示するjsを呼ぶ
  • フラグがfalse: 画面遷移 + actionを呼ぶ

hoge.hogehogeでは入力値によってhoge.flgを更新している。

実装例
<h:inputText id="flg" value="#{hoge.flgValue}">
	<f:ajax event="change" listener="#{hoge.hogehoge}" execute="@this" render="@this is_modal"/>
</h:inputText>

<h:panelGroup id="is_modal">
    <h:panelGroup rendered="#{hoge.flg}">
        <a href="" onclick="open_modal">モーダル表示</a>
    </h:panelGroup>
    <h:panelGroup rendered="#{not hoge.flg}">
        <h:commandLink actionListener="#{hoge.fugafuga}" action="#{hoge.piyopiyo}">登録する</h:commandLink>
    </h:panelGroup>
</h:panelGroup>
0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?