@Documented @Target(value=TYPE) @Retention(value=RUNTIME) public @interface Templated
Composite
.
Indicates that the annotated class will participate in the Errai UI templating framework. Instances of the annotated
Composite
widget must be retrieved via Inject
or Instance
references in bean classes.
Unless otherwise specified in the value()
and provider()
attributes, a corresponding
ComponentName.html file must be placed in the same directory on the class-path as the custom ComponentName type.
Example:
package org.example; @Templated public class CustomComponent extends Composite { }And the corresponding HTML template:
<form> <legend>Log in to your account</legend> <label for="username">Username</label> <input data-field="username" id="username" type="text" placeholder="Username"> <label for="password">Password</label> <input data-field="password" id="password" type="password" placeholder="Password"> <button data-field="login" >Log in</button> <button data-field="cancel" >Cancel</button> </form>
Each element with a id
, data-field
or class
attribute may be bound to a
field, method, or constructor parameter in the annotated class, using the DataField
annotation. Events
triggered by elements or widgets in the template may be handled using the EventHandler
annotation to
specify handler methods.
package org.example; @Templated public class CustomComponent extends Composite { @Inject @DataField private TextBox username; @Inject @DataField private TextBox password; @Inject @DataField private Button login; @Inject @DataField private Button cancel; @EventHandler("login") private void doLogin(ClickEvent event) { // log in } }
Obtaining a widget reference via Inject
:
@ApplicationScoped public class ExampleBean { @Inject private CustomComponent comp; }
Obtaining widget references on demand, via Instance
. One may also create multiple instances of a
Templated
widget using this approach:
@ApplicationScoped public class ExampleBean { @Inject Instance<CustomComponent> instance; public CustomComponent getNewComponent() { return instance.get(); } }
See also: DataField
, Bound
, AutoBound
, EventHandler
, SinkNative
Modifier and Type | Optional Element and Description |
---|---|
Class<? extends TemplateProvider> |
provider
Specifies a
TemplateProvider that is used to supply a template at run-time i.e. |
String |
value
Specifies the resource path (
com/example/foo/CompositeComponent.html ) and fragment (
#name ) of the HTML template with which the annotated widget should be composited. |
public abstract String value
com/example/foo/CompositeComponent.html
) and fragment (
#name
) of the HTML template with which the annotated widget should be composited.
The resource path is the location of the HTML file on the classpath. If omitted, this defaults to the fully qualified class name of the annotated type, plus `.html`. If the fragment is omitted, composition will be performed using the first single element found (and all inner HTML) in the specified template.
The fragment corresponds to an element with matching id
, data-field
or
class
attribute. If specified, this singleelement (and all inner HTML) will be used as the root
of the widget.
public abstract Class<? extends TemplateProvider> provider
TemplateProvider
that is used to supply a template at run-time i.e.
ServerTemplateProvider
. By default, and if omitted, templates must be present at compile-time at the
class-path location specified by value()
.Copyright © 2013-2015 JBoss, a division of Red Hat. All Rights Reserved.