目录

Remove

ui:remove标签用于防止在客户端呈现JSF特定代码。 它特别用于防止注释掉的代码在客户端呈现。

使用HTML注释将JSF标记注释掉

<!-- JSF code commented out -->
<!-- 
<h:commandButton value = "Ok" />  
-->

渲染输出 (Rendered Output)

<!-- JSF code commented out -->
<!-- 
<h:commandButton value = "Ok" />  
-->

现在使用删除标记,我们将在渲染输出中看到以下更改。

使用删除标记注释掉JSF标记

<!-- JSF code commented out -->
<ui:remove>
   <h:commandButton value = "Ok" />  
</ui:remove>

渲染输出 (Rendered Output)

<!-- JSF code commented out -->

例子 Example Application

让我们创建一个测试JSF应用程序来测试JSF中的模板标签。

描述
1com.iowiki.test包下创建一个名为helloworld的项目,如JSF - First Application一章中所述。
2 修改home.xhtml ,如下所述。 保持其余文件不变。
3 编译并运行应用程序以确保业务逻辑按照要求运行。
4 最后,以war文件的形式构建应用程序并将其部署在Apache Tomcat Webserver中。
5 使用适当的URL启动Web应用程序,如下面的最后一步所述。

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 - First Application章节中那样编译和运行应用程序。 如果您的应用程序一切正常,您将看到一个空白页面。

查看页面的来源,您将看到以下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>
↑回到顶部↑
WIKI教程 @2018