Jsf-applicationevents-tag
JSF-アプリケーションイベント
JSFは、JSFアプリケーションライフサイクル中にアプリケーション固有のタスクを実行するシステムイベントリスナーを提供します。
S.No | System Event & Description |
---|---|
1 |
PostConstructApplicationEvent アプリケーションの起動時に起動します。 アプリケーションの起動後に初期化タスクを実行するために使用できます。 |
2 |
PreDestroyApplicationEvent アプリケーションがシャットダウンしようとしているときに起動します。 アプリケーションをシャットダウンする前に、クリーンアップタスクを実行するために使用できます。 |
3 |
PreRenderViewEvent JSFページが表示される前に発生します。 ユーザーを認証し、JSFビューへの制限付きアクセスを提供するために使用できます。 |
システムイベントは、次の方法で処理できます。
S.No | Technique & Description |
---|---|
1 |
SystemEventListener SystemEventListenerインターフェイスを実装し、faces-config.xmlにsystem-event-listenerクラスを登録します |
2 |
Method Binding マネージドBeanメソッドの名前をf:eventの_listener_属性に渡します。 |
SystemEventListener
SystemEventListenerインターフェイスを実装します。
システムイベントのカスタムシステムイベントリスナーをfaces-config.xmlに登録します。
メソッドのバインド
メソッドを定義する
上記の方法を使用します。
応用例
テストJSFアプリケーションを作成して、JSFのシステムイベントをテストしましょう。
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 CustomSystemEventListener.java file under a package com.finddevguides.test. Modify it as explained below |
4 | Modify home.xhtml as explained below. |
5 | Create faces-config.xml in WEB-INF folder.Modify it 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
CustomSystemEventListener.java
home.xhtml
faces-config.xhtml
すべての変更を完了したら、JSF-最初のアプリケーションの章で行ったようにアプリケーションをコンパイルして実行します。 すべてがアプリケーションで問題ない場合、次の結果が生成されます。
Webサーバーコンソールの出力を調べます。 次の結果が表示されます。