@Retention(value=SOURCE) @Target(value=METHOD) public @interface HTMLDialog
<!DOCTYPE html> <html> <head> <title>Base question</title> <meta charset="UTF-8"> </head> <body> <div>Hello World! How are you?</div> <!-- you need to check the checkbox to enabled the OK button --> <input type="checkbox" data-bind="checked: ok">OK?<br> <!-- enabled with checkbox is checked --> <button id='ok' hidden data-bind="enable: ok">Good</button> <button id='bad' hidden>Bad</button> </body> </html>The
dialog.html
page defines two buttons as hidden -
they are re-rendered by the embedding "chrome" (for example as Swing buttons),
but they can be enabled/disabled. For example the ok
property
(defined in the Java model below) connects the state of the checkbox and
the Good button.
@Model
(className = "AskCtrl", targetId = "", properties = { @Property
(name = "ok", type = boolean.class) }) public final class AskQuestion implementsActionListener
{ @HTMLDialog
(url = "dialog.html", className = "AskPages") staticHTMLDialog
.OnSubmit showHelloWorld(boolean checked) { AskCtrl model = new AskCtrl(checked).applyBindings(); return (buttonId) -> { // called when user presses a buttonSystem
.out.println("User selected: " + buttonId); // return false to prevent dialog from closing return true; }; } @Override
public void actionPerformed(ActionEvent
e) { // shows dialog with a question, checkbox is checked by default // AskPages is automatically generated class AskPages.showHelloWorld(true); } }
The method is generated into AskPages
class (specified in the
className
attribute)
in the same package and has the same name,
and parameters as the method annotated by the HTMLDialog
annotation.
When the method AskPages.showHelloWorld(true)
is invoked, it opens a dialog, loads an HTML page dialog.html
into it. When the page is
loaded, it calls back the method AskQuestion.showHelloWorld
and passes it
its own arguments. The method is supposed to make the page live, preferably
by using Model
generated class and calling
applyBindings()
on it. The method is suggested to return
an instance of HTMLDialog.OnSubmit
callback to be notified about user pressing
one of the dialog buttons.
The HTML page may contain hidden <button>
elements. If it does so,
those buttons are copied to the dialog frame and displayed underneath the page.
Their enabled/disabled state reflects the state of the buttons in the page.
When one of the buttons is selected a callback to HTMLDialog.OnSubmit
instance
is made. If it returns true
, the dialog closes otherwise its closing
is prevented. A null
'id' signals user closing or cancelling the dialog.
By default, if the HTML defines no hidden
<button>
elements, two buttons are added. One representing
the OK choice (with id="OK"
) and one representing
the cancel choice (with null
id). Both buttons are always
enabled. One can check the callback 'id'
to be "OK"
to know whether the user approved the dialog.
Modifier and Type | Required Element and Description |
---|---|
String |
url
URL of the page to display.
|
Modifier and Type | Optional Element and Description |
---|---|
String |
className
Name of the file to generate the method that opens the dialog
into.
|
String[] |
resources
List of resources to make available for the
HTMLDialog.url() page. |
String[] |
techIds
Selects some of provided technologies.
|
public abstract String url
nbresloc
protocol - as such the HTML page can be L10Ned
later by adding classical L10N suffixes. E.g. index_cs.html
will take precedence over index.html
if the user is
running in Czech Locale
.public abstract String[] resources
HTMLDialog.url()
page.
The rendering system shall make sure these resources are available when
the main page
is loaded and are at the same relative
locations like the page.public abstract String className
public abstract String[] techIds
technology ids
. One can specify the preferred ones
to use in this NetBeans component by using this attribute.