个性化阅读
专注于IT技术分析

PrimeFaces SelectBooleanButton示例

点击下载

本文概述

<p:selectBooleanButton>用于在JSF应用程序中创建BooleanButton。我们可以使用它来获取用户的布尔输入。它提供了一个与用户交互的切换按钮。

SelectBooleanButton属性

下表包含InputTextarea组件的属性。

Attribute Default value 返回类型 Description
id null String 它是组件的唯一标识符。
rendered true Boolean 它返回布尔值以指定组件的呈现。
binding null Object 它用于设置一个表达式, 该表达式映射到后备bean中的服务器端UIComponent实例。
value null Object 它保存引用列表的组件的值。
converter null Converter/String 它用于设置一个表达式或文字文本, 以定义该组件的转换器。
immediate false Boolean 用于设置布尔值。如果value为true, 则在此组件的应用请求值阶段执行过程验证逻辑。
required false Boolean 用于根据需要制作组件。
requiredMessage null String 它用于设置在必填字段验证失败时显示的消息。
onchange null String 它用于在值更改时调用方法。
style null String 用于设置组件的内联样式。
onIcon null String 用于设置选择按钮时显示的图标。
offIcon null String 用于取消选择按钮时显示的图标。
onfocus null String 当按钮获得焦点时执行。
onblur null String 当按钮失去焦点时执行。

例子

在下面的示例中, 我们正在实现<p:selectBooleanButton>组件。本示例包含以下文件。

JSF文件

// boolean-button.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://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Boolean Button</title>
</h:head>
<h:body>
<h2>PrimeFaces Boolean Button Example</h2>
<h:form>
<h:panelGrid columns="2" style="margin-bottom:10px" cellpadding="5">
<h:outputText value="I accept terms and conditions: " />
<p:selectBooleanButton id="bol" value="#{booleanButton.checkValue}" onLabel="Yes" offLabel="No" style="width:80px" onIcon="ui-icon-check" offIcon="ui-icon-close"/>
</h:panelGrid>
</h:form>
</h:body>
</html>

ManagedBean

// BooleanButton.java

package com.srcmini;
import javax.faces.bean.ManagedBean;
@ManagedBean
public class BooleanButton {
private boolean checkValue;   
public boolean isCheckValue() {
return checkValue;
}
public void setCheckValue(boolean checkValue) {
this.checkValue = checkValue;
}
}

输出

Primefaces Selectbooleanbutton 1

单击按钮后, 它切换为是。

Primefaces Selectbooleanbutton 2
赞(0)
未经允许不得转载:srcmini » PrimeFaces SelectBooleanButton示例

评论 抢沙发

评论前必须登录!