Class UIButtonSpecJSActionToggle
The toggle button has two states:
- When the button is deactivated: OFF
- When the button is activated: ON
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:
-
when the button is activated,
the 'ON' confirmation message is displayed if it has been set
(see
UIButtonSpec.setConfirmationMessage(UserMessage)
), thenJSCmdOn
is called -
when the button is deactivated,
the 'OFF' confirmation message is displayed if it has been set
(see
setConfirmationMessageOff(UserMessage)
), thenJSCmdOff
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)
.
- Since:
- 5.2.3
-
Field Summary
Modifier and TypeFieldDescriptionstatic final boolean
Use this constant withsetInitialState(boolean)
to set the button to 'OFF'.static final boolean
Use this constant withsetInitialState(boolean)
to set the button to 'ON'.static final String
HTTP request parameter value sent if the checkbox behavior is enabled and the form is submitted with the button set to 'ON'. -
Constructor Summary
ConstructorDescriptionUIButtonSpecJSActionToggle
(UserMessage aLabel, String aJSCmdOn, String aJSCmdOff) -
Method Summary
Modifier and TypeMethodDescriptionfinal UserMessage
final boolean
final String
final String
final String
final void
setConfirmationMessageOff
(UserMessage confirmationMessageOff) Sets a message to confirm the action performed when the button is deactivated.final void
setInitialState
(boolean initialState) Sets the initial state of this button.final void
setInputName
(String inputName) Enables checkbox behavior by setting its input name in the current form.Methods inherited from class com.orchestranetworks.ui.UIButtonSpec
getButtonIcon, getButtonLayout, getConfirmationMessage, getIconURL, getId, getLabel, getRelief, getTooltip, hasConfirmationMessage, isDefaultButton, isDisabled, isExcludedFromTabFocus, setButtonIcon, setButtonLayout, setConfirmationMessage, setCssClass, setDefaultButton, setDisabled, setExcludedFromTabFocus, setIconURL, setId, setLabel, setRelief, setTooltip
-
Field Details
-
ON
public static final boolean ONUse this constant withsetInitialState(boolean)
to set the button to 'ON'.- See Also:
-
OFF
public static final boolean OFFUse this constant withsetInitialState(boolean)
to set the button to 'OFF'.- See Also:
-
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'.- See Also:
-
-
Constructor Details
-
UIButtonSpecJSActionToggle
- Parameters:
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'.
-
-
Method Details
-
getJSCmdOn
- Returns:
- the JavaScript command invoked when this button is set to 'ON'.
-
getJSCmdOff
- Returns:
- the JavaScript command invoked when this button is set to 'OFF'.
-
getInitialState
public final boolean getInitialState() -
setInitialState
public final void setInitialState(boolean initialState) Sets the initial state of this button. By default, the button is initially deactivated (OFF
).The state of the button can also be managed in JavaScript with the function
UIJavaScriptWriter.addJS_setStateToToggleButton(String, String)
. -
setConfirmationMessageOff
Sets a message to confirm the action performed when the button is deactivated. A "Yes"/"Cancel" dialog will open when the button is deactivated.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)
.- Parameters:
confirmationMessageOff
- the confirmation message to set to the button when it turns OFF.
-
getConfirmationMessageOff
- Returns:
- the confirmation message of the button when it is deactivated,
null
if it is not set.To get the confirmation message of the button when it is activated, call
UIButtonSpec.getConfirmationMessage()
.
-
getInputName
- See Also:
-
setInputName
Enables checkbox behavior by setting its input name in the current form.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 beON_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
.- Parameters:
inputName
- the value of the attributename
of the input checkbox, namely the name of the HTTP request parameter sent when the form is submitted.- See Also:
-