Jsf-remove-tag
提供:Dev Guides
JSF-ui:removeタグ
ui:removeタグは、JSF固有のコードがクライアント側でレンダリングされるのを防ぐために使用されます。 特に、コメントアウトされたコードがクライアント側でレンダリングされるのを防ぐために使用されます。
HTMLコメントを使用してコメントアウトされたJSFタグ
<!-- JSF code commented out -->
<!--
<h:commandButton value = "Ok"/>
-->
レンダリングされた出力
<!-- JSF code commented out -->
<!--
<h:commandButton value = "Ok"/>
-->
removeタグを使用すると、レンダリングされた出力に次の変更が表示されます。
タグの削除を使用してコメント化されたJSFタグ
<!-- JSF code commented out -->
<ui:remove>
<h:commandButton value = "Ok"/>
</ui:remove>
レンダリングされた出力
<!-- JSF code commented out -->
応用例
テスト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 home.xhtml as explained below. Keep rest of the files unchanged. |
3 | Compile and run the application to make sure business logic is working as per the requirements. |
4 | Finally, build the application in the form of war file and deploy it in Apache Tomcat Webserver. |
5 | Launch your web application using appropriate URL as explained below in the last step. |
home.xhtml
<?xml version = "1.0" encoding = "UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml"
xmlns:h = "http://java.sun.com/jsf/html"
xmlns:ui = "http://java.sun.com/jsf/facelets">
<h:head>
<title>JSF tutorial</title>
</h:head>
<h:body>
<ui:remove>
<h:commandButton value = "Ok"/>
</ui:remove>
<!--
<h:commandButton value = "Cancel"/>
-->
</h:body>
</html>
すべての変更を完了したら、JSF-最初のアプリケーションの章で行ったようにアプリケーションをコンパイルして実行します。 アプリケーションに問題がなければ、空のページが表示されます。
ページのソースを表示すると、次のHTMLテキストが表示されます。
home.jsf
<?xml version = "1.0" encoding = "UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<title>JSF tutorial</title>
</head>
<body>
<!--
<h:commandButton value = "Cancel"/>
-->
</body>
</html>