codecamp

JSF 删除示例

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


JSF 资源包示例
JSF Facelets模板示例
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }