@Retention(value=SOURCE) @Target(value=METHOD) public @interface OpenHTMLRegistration
HTML for Java
integration). The essential
aspect is to create an HTML page and reference its location via OpenHTMLRegistration.url()
attribute.
The page may contain any JavaScript, but as we are Java developers, it is
preferrable to rather use HTML for Java API.
In such case the associated static method (which is annotated by this annotation) will be
called once the HTML page is loaded. One is expected to instantiate class generated
by the Model
annotation and call applyBindings()
on it. Here is an example:
@The above would display a new action in Toolbar and in Menu that would, upon invocation, open up a new component displaying theModel
(className = "UI", targetId = "", properties = { @Property
(name = "text", type =String
.class) }) public final class UICntrl { // callback when Submit button is pressed @Function
static void submit(UI model) {System
.err.println("You are feeling " + model.getText()); } // // register the action to the UI // @ActionID
( category = "Tools", id = "my.sample.HtmlHelloWorld" ) @ActionReferences
({ @ActionReference
(path = "Menu/Tools"), @ActionReference
(path = "Toolbars/File"),}) @NbBundle
.Messages("CTL_OpenHtmlHelloWorld=Open HTML Hello World!") @OpenHTMLRegistration
( url = "ui.html", displayName = "#CTL_OpenHtmlHelloWorld" ) public static UI onPageLoad() { return new UI("Hello World!").applyBindings(); } }
ui.html
page. The page can use
Knockout.js bindings like
<input data-bind="textInput: text"></input>
to reference
properties defined by the Model
annotation in the generated class
UI
:
<!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>
In addition to the above, there is a special support for influencing action context
and thus turning on and off various actions shown in menu and toolbar. Just
define
and put into it fully qualified names of classes you want to expose in the context.
Those classes should be public and have public constructor that takes instance of the model
class returned from the annotated method (e.g. @Property
(name = "context", type = String.class, array = true)UI
in the above example). The
system will instantiate them appropriatelly and will make sure they are available in the action
context. If the interface also implements Closeable
, its close method is invoked once
the instance is removed from the context to handle clean up.
Modifier and Type | Required Element and Description |
---|---|
String |
displayName |
String |
url
URL to the HTML page to display in the view.
|
public abstract String url
public abstract String displayName
public abstract String iconBase
public abstract String[] techIds
technology ids
. One can specify the preferred ones
to use in this NetBeans component by using this attribute.