📅  最后修改于: 2021-01-08 04:18:27             🧑  作者: Mango
它用于从用户输入布尔值作为输入。这是一个可切换为开或关的按钮。我们可以使用组件创建它。它还提供了下表中列出的各种属性。
Attribute | Default value | Type | Description |
---|---|---|---|
onLabel | on | String | It is used to set label for on state. |
offLabel | off | String | It is used to set label for off state. |
label | null | String | It is used to set label for the component. |
disabled | null | String | It is used to disables or enables the switch. |
onchange | false | Boolean | It is used to call client script on value change event. |
style | null | String | It is used to set inline CSS of the main container. |
tabindex | null | String | It specifies the tab order of an element. |
showLabels | null | String | It is used to set the visibility of the labels. |
onfocus | null | String | It executes when component receives focus. |
onblur | null | String | It executes when component loses focus. |
在下面的示例中,我们正在实现组件。本示例包含以下文件。
// switch.xhtml
Switch
// SwitchDemo.java
package com.javatpoint;
import javax.faces.bean.ManagedBean;
@ManagedBean
public class Slider {
private int value;
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
}
}
输出: