菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻

JSF 删除示例

原创
05/13 14:22 更新

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 com.lmonkey.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;
  }
}

运行

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

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

http://localhost:8080/simple-webapp/demo.xhtml
综合评分:9.9 评分 请对本文进行纠错,及学习过程中有困难疑惑可在此进行讨论