Errai 3.0.1-SNAPSHOT

org.jboss.errai.ui.shared.api.annotations
Annotation Type Templated


@Documented
@Target(value=TYPE)
@Retention(value=RUNTIME)
public @interface Templated

Must be used only on classes extending from 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() attribute, 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 data-field 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

Author:
Lincoln Baxter, III

Optional Element Summary
 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.
 

value

public abstract 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.

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 data-field value. If specified, this single element (and all inner HTML) will be used as the root of the widget.

Default:
""

Errai 3.0.1-SNAPSHOT

Copyright © 2013-2014 JBoss, a division of Red Hat. All Rights Reserved.