Switch

Switches are toggle element that switch between an Off and On state on tap or click. A switch is backed by a checkbox input.

There is a client side Widget API as well as AJAX server callbacks available.


Example
Documentation

<t:switch value="#{bean.booleanValue}">
    <f:ajax listener="#{controller.onSwitch}" render="noticiation"/>
</t:switch>

<button onclick="TW('myswitch').toggle()">Toggle with Widget API</button>

Switches are toggle element that switch between an Off and On state on tap or click. A switch is backed by a checkbox input.

Info
Tag name switch
Component type io.tornadofaces.component.Switch
Renderer type io.tornadofaces.component.SwitchRenderer
Attributes
NameDescriptionRequired
valueThe valuefalse
styleClassStyles to apply to the switch.false
styleCSS Styles applied to the switch.false
sizeThe size of the button: valid options are small, large. No value means default/medium. false
onChangeJavaScript callback when switch is flippedfalse
widgetVarWidget variable name, accessible via TW('widgetVar') and TornadoFaces.widgets.widgetVar. false
renderedShould this component be rendered?false
Client Side Callbacks

onChange is called as the switch is flipped.

function onChange(switch) {
    //
}
Ajax Behavior Events

change will be called when a switch is flipped

<t:switch>
    <f:ajax event="change" listener="#{controller.onChange}">
</t:switch>
public void onChange(SwitchEvent event) {
    Switch _switch = event.getSwitch();
}

The listener will be called with an instance of io.tornadofaces.event.SwitchEvent that contains a reference to the switch.

Client Side API

Widget: TornadoFaces.widget.Switch

Method Params Return type Description
toggle() void Toggle the checked state.