JSF 2.0では、

<h:button/>



<h:commandButton/>

の両方のタグを使用して、タイプボタンのHTML入力エレメントをレンダリングします。

1. JSF h:commandButtonの例

JSF 1.xから ”

h:commandButton

“タグがリリースされたので、 ”

action

“属性でナビゲーション結果を返すBeanを宣言できます。 JavaScriptが無効なブラウザでは、ナビゲーションはフォームポスト経由で処理されるため、まだ動作しています。

{空} 1。送信ボタン

…​.//JSF
<h:commandButton value=”submit” type=”submit” action=”#{user.goLoginPage}”/>
<input type=”submit” name=”xxx” value=”submit”/>

{空} 2。リセットボタン

....//JSF
<h:commandButton value="reset" type="reset"/>
//HTML output
<input type="reset" name="xxx" value="reset"/>

{空} 3。通常ボタン

…​.//JSF
<h:commandButton value=”button” type=”button”/>
<input type=”button” name=”xxx” value=”button”/>

{空} 4。 onclickイベントのある通常のボタン

....//JSF
<h:commandButton value="Click Me" type="button" onclick="alert('h:commandButton');"/>
//HTML output
<input type="button" name="xxx" value="Click Me" onclick="alert('h:commandButton');"/>

2. JSF h:ボタンの例



h:button

“はJSF 2.0の新しいタグです。ナビゲーション結果を直接 ”

outcome

“属性で宣言できます。上記の “h:commandButton”のような結果を返すためにBeanを呼び出す必要はありません。しかし、ブラウザがJavaScriptを無効にしていると、 ”

h:button

“タグが “onclick”イベントを生成して “window.location.href”を介してナビゲーションを処理するため、ナビゲーションは失敗します。例を参照してください。

{空} 1。結果のない通常のボタン

…​.//JSF
<h:button value=”buton”/>
<input type=”button”
onclick=”window.location.href=’/JavaServerFaces/faces/currentpage.xhtml; return false;”
value=”buton”/>

__P.S outcome属性を省略すると、現在のページURLが結果として扱われます。

{空} 2。結果のある通常のボタン

....//JSF
<h:button value="buton" outcome="login"/>
//HTML output
<input type="button"
   onclick="window.location.href='/JavaServerFaces/faces/login.xhtml; return false;"
   value="buton"/>

{空} 3。 JavaScriptの標準ボタン。

…​.//JSF
<h:button value=”Click Me” onclick=”alert(‘h:button’);”/>
<input type=”button”
onclick=”alert(‘h:button’);window.location.href=’/JavaServerFaces/faces/page.xhtml;return false;”
value=”Click Me”/>

** 私の考え... **  JSF 2.0がこの "**  h:button ** "タグをリリースした理由はまったく分かりません。JavaScriptのリダイレクトは実用的ではありません。最高のものは、 "**  h:commandButton ** "タグに "**  outcome ** "属性を統合することです。将来のリリースでそれが可能であることを願っています。

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

ダウンロード - リンク://wp-content/uploads/2010/10/JSF-2-Button-CommandButton-Example.zip[JSF-2-Button-CommandButton-Example.zip](10KB)

===== リファレンス

.  https://javaserverfaces.dev.java.net/nonav/docs/2.0/pdldocs/facelets/h/button.html[JSF

<h:button/> JavaDoc]。 https://javaserverfaces.dev.java.net/nonav/docs/2.0/pdldocs/facelets/h/commandButton.html[JSF

<h:commandButton/> JavaDoc]

リンク://タグ/ボタン/[ボタン]リンク://タグ/jsf2/[jsf2]