Jsf-actionlistener-tag
提供:Dev Guides
JSF-actionListener
ユーザーがh:commandButtonやh:linkなどのコンポーネントを操作すると、JSFは2つの方法で処理できるアクションイベントを発生させます。
S.No | Technique & Description |
---|---|
1 |
Method Binding UIコンポーネントの_actionListener_属性でマネージドBeanメソッドの名前を渡します。 |
2 |
ActionListener ActionListenerインターフェースを実装し、実装クラス名をUIコンポーネントの_actionListener_属性に渡します。 |
メソッドのバインド
メソッドを定義する
上記の方法を使用してください
ActionListener
ActionListenerを実装する
リスナーメソッドを使用する
応用例
テストJSFアプリケーションを作成して、JSFのactionListenerをテストしましょう。
Step | Description |
---|---|
1 | Create a project with a name helloworld under a package com.finddevguides.test as explained in the JSF - First Application chapter. |
2 | Modify UserData.java file as explained below. |
3 | Create UserActionListener.java file under a package com.finddevguides.test. Modify it as explained below. |
4 | Modify home.xhtml as explained below. Keep the rest of the files unchanged. |
5 | Modify result.xhtml as explained below. Keep the rest of the files unchanged. |
6 | Compile and run the application to make sure the business logic is working as per the requirements. |
7 | Finally, build the application in the form of war file and deploy it in Apache Tomcat Webserver. |
8 | Launch your web application using appropriate URL as explained below in the last step. |
UserData.java
UserActionListener.java
home.xhtml
result.xhtml
すべての変更を完了したら、JSF-最初のアプリケーションの章で行ったようにアプリケーションをコンパイルして実行します。 すべてがアプリケーションで問題ない場合、次の結果が生成されます。
送信ボタンをクリックします。 次の結果が表示されます。