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

PrimeFaces SelectManyCheckbox复选框例子

点击下载

本文概述

它用于从给定选项中选择多个值。当我们要从集合中获取多个用户输入时, 这很有用。我们可以使用<p:selectManyCheckbox>组件在JSF应用程序中创建SelectManyCheckbox。

它具有下表列出的各种属性。

ManyButton属性

Attribute 默认值 Return type Description
id null String 它是组件的唯一标识符。
rendered true Boolean 它用于指定组件的呈现。
value null obejct 用于设置组件的值。
required false Boolean 用于根据需要标记组件。
requiredMessage null String 它用于设置在必填字段验证失败时显示的消息。
disabled false Boolean 用于禁用组件。
label null String 用于设置用户可显示名称。
layout lineDirection String 它用于设置复选框的布局。
columns 0 Integer 它用于指定网格布局中的列数。
onchange null String 它用于在值更改时执行脚本。
style null String 它用于设置组件的内联CSS。
tabindex null String 用于按跳位顺序设置组件的位置。

结构样式类

下表包含SelectManyCheckbox的结构样式类。

Style Class Applies
.ui-selectmanycheckbox 它适用于主容器元素。
的.ui-chkbox 它适用于复选框的容器。
.ui-chkbox-box 适用于复选框图标的容器。
.ui-chkbox-icon 它适用于复选框图标。

例子

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

JSF文件

// selectManyCheckbox.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"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<title>Primefaces ManyCheckBox</title>
</h:head>
<h:body>
<h:form>
<h3 style="margin-top:0px">Select Courses</h3>
<p:selectManyCheckbox id="basic" value="#{manyCheckBox.selectedCourse}">
<f:selectItem itemLabel="J2SE" itemValue="J2SE" />
<f:selectItem itemLabel="Servlet" itemValue="Servlet" />
<f:selectItem itemLabel="Spring" itemValue="Spring" />
</p:selectManyCheckbox>
<br/>
<p:commandButton value="Submit" update="display-courses" oncomplete="PF('dlg').show()" icon="ui-icon-check" />
<p:dialog header="Courses" modal="true" showEffect="clip" widgetVar="dlg" resizable="true">
<p:outputPanel id="display-courses">
<p:dataList value="#{manyCheckBox.selectedCourse}" var="example">
<f:facet name="header">
Course Name
</f:facet>
#{example}
</p:dataList>
</p:outputPanel>
</p:dialog>
</h:form>
</h:body>
</html>

ManagedBean

// ManyCheckBox.java

package com.srcmini;
import javax.faces.bean.ManagedBean;
@ManagedBean
public class ManyCheckBox {
private String[] selectedCourse;
public String[] getSelectedCourse() {
return selectedCourse;
}
public void setSelectedCourse(String[] selectedCourse) {
this.selectedCourse = selectedCourse;
}
}

输出

PrimeFaces SelectManyCheckbox复选框1
PrimeFaces SelectManyCheckbox复选框2
赞(0)
未经允许不得转载:srcmini » PrimeFaces SelectManyCheckbox复选框例子

评论 抢沙发

评论前必须登录!