public class UIButtonSpecJSActionToggle extends UIButtonSpec
The toggle button has two states:
When 'OFF', the user can click the button and it stays in the 'ON' state. When 'ON', the user can click the button and it stays in the 'OFF' state.
Two JavaScript actions are associated with this button:
UIButtonSpec.setConfirmationMessage(UserMessage)
), then JSCmdOn
is called
setConfirmationMessageOff(UserMessage)
), then JSCmdOff
is called
The toggle button can be used in a <form>
and acts like a checkbox.
To enable this feature, the input name must be set.
If the state of the button is 'ON', the name will be sent with the value ON_PARAMETER_VALUE
,
if the state of the button is 'OFF', nothing will be sent.
The state of the button can also be managed in JavaScript
with the function UIJavaScriptWriter.addJS_setStateToToggleButton(String, String)
.
Modifier and Type | Field and Description |
---|---|
static boolean |
OFF
Use this constant with
setInitialState(boolean) to set the button to 'OFF'. |
static boolean |
ON
Use this constant with
setInitialState(boolean) to set the button to 'ON'. |
static String |
ON_PARAMETER_VALUE
HTTP request parameter value sent if the checkbox behavior is enabled and the form
is submitted with the button set to 'ON'.
|
Constructor and Description |
---|
UIButtonSpecJSActionToggle(UserMessage aLabel,
String aJSCmdOn,
String aJSCmdOff) |
Modifier and Type | Method and Description |
---|---|
UserMessage |
getConfirmationMessageOff() |
boolean |
getInitialState() |
String |
getInputName() |
String |
getJSCmdOff() |
String |
getJSCmdOn() |
void |
setConfirmationMessageOff(UserMessage confirmationMessageOff)
Sets a message to confirm the action performed when the button is deactivated.
|
void |
setInitialState(boolean initialState)
Sets the initial state of this button.
|
void |
setInputName(String inputName)
Enables checkbox behavior by setting its input name in the current form.
|
getButtonIcon, getButtonLayout, getConfirmationMessage, getIconURL, getId, getLabel, getRelief, getTooltip, hasConfirmationMessage, isDefaultButton, isDisabled, isExcludedFromTabFocus, setButtonIcon, setButtonLayout, setConfirmationMessage, setCssClass, setDefaultButton, setDisabled, setExcludedFromTabFocus, setIconURL, setId, setLabel, setRelief, setTooltip
public static final boolean ON
setInitialState(boolean)
to set the button to 'ON'.public static final boolean OFF
setInitialState(boolean)
to set the button to 'OFF'.public static final String ON_PARAMETER_VALUE
setInputName(String)
,
Constant Field Valuespublic UIButtonSpecJSActionToggle(UserMessage aLabel, String aJSCmdOn, String aJSCmdOff)
aLabel
- the label of the button.aJSCmdOn
- the JavaScript command to call when the button is set to 'ON'.aJSCmdOff
- the JavaScript command to call when the button is set to 'OFF'.public final String getJSCmdOn()
public final String getJSCmdOff()
public final boolean getInitialState()
public final void setInitialState(boolean initialState)
OFF
).
The state of the button can also be managed in JavaScript
with the function UIJavaScriptWriter.addJS_setStateToToggleButton(String, String)
.
public final void setConfirmationMessageOff(UserMessage confirmationMessageOff)
If the user clicks "Cancel" in the dialog, the action will not be called.
To set a message to confirm the action when the button is activated,
use UIButtonSpec.setConfirmationMessage(UserMessage)
.
confirmationMessageOff
- the confirmation message to set to the button when it turns OFF.public final UserMessage getConfirmationMessageOff()
null
if it is not set.
To get the confirmation message of the button when it is activated,
call UIButtonSpec.getConfirmationMessage()
.
public final String getInputName()
setInputName(String)
public final void setInputName(String inputName)
The toggle button can be used in a <form>
, to act like a checkbox.
If the state of the button is 'ON' upon form submission, the value sent will be ON_PARAMETER_VALUE
,
if the state of the button is 'OFF', no value will be sent.
By default, the checkbox feature is not enabled and input name is null
.
inputName
- the value of the attribute name
of the input checkbox,
namely the name of the HTTP request parameter sent when the form is submitted.