Radio button elements
A RadioFormElement
writes a <input type="radio">
tag to the output.
It shares the same functionality as the CheckboxFormElement, but uses the radio
type instead.
Element and builder
The ViewElement
implementation for a radio button element is a RadioFormElement
which is a CheckboxFormElement
that specifies a different input type.
A builder can be created via the BootstrapElements.bootstrap.builders#radio
factory methods.
Thymeleaf model writer
The RadioFormElementWriter
is a specialized version of the CheckboxFormElementWriter that ensures that the label and/or wrapping element are closed correctly.
Examples
Creating a radio button
import static com.foreach.across.modules.bootstrapui.ui.factories.BootstrapViewElements.bootstrap;
bootstrap.builders.radio()
.build();
Providing a label
import static com.foreach.across.modules.bootstrapui.ui.factories.BootstrapViewElements.bootstrap;
bootstrap.builders.radio()
.label( "John" ) (1)
.build()
1 | A label for a radio button can also be provided using the text method on the OptionFormElementBuilder .
The value set via the label method always takes precedence over the text value. |
Radiobutton list
import static com.foreach.across.modules.bootstrapui.ui.factories.BootstrapViewElements.bootstrap;
bootstrap.builders.radioList()
.label( "John" )
.add( bootstrap.builders.option.option().text( "" ).value( 0 ) )
.add( bootstrap.builders.option.option().text( "option 1" ).value( 1 ) )
.build()