JSF 删除示例

2018-09-27 15:44 更新

JSF教程 - JSF删除示例


我们可以使用“ui:remove"标签来定义要删除的内容。

通过使用“ui:remove"标签,我们可以认为包含“ui:remove"标签的标签被注释掉。

<ui:remove>
<h:commandButton type="button" 
  value="#{msg.buttonLabel}" />
</ui:remove>    

变为

<!--
<h:commandButton type="button" 
  value="#{msg.buttonLabel}" />
</ui:remove>       
-->

以下代码显示如何使用ui:remove标记。


例子

以下代码来自demo.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:body>
      <ui:remove>
      <h:commandButton type="button" 
        value="#{msg.buttonLabel}" />
      </ui:remove>       
    </h:body>
</html>

下面的代码来自UserBean.java。

package cn.w3cschool.common;

import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
 
@ManagedBean(name="msg")
@SessionScoped
public class UserBean implements Serializable{

  String buttonLabel = "Submit";

  public String getButtonLabel() {
    return buttonLabel;
  }

  public void setButtonLabel(String buttonLabel) {
    this.buttonLabel = buttonLabel;
  }

}
下载 Remove.zip

运行

将生成的WAR文件从目标文件夹复制到Tomcat部署文件夹,并运行Tomcat-Install-folder/bin/startup.bat。

Tomcat完成启动后,在浏览器地址栏中键入以下URL。

http://localhost:8080/simple-webapp/demo.xhtml


以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号