Errai 3.0.1-SNAPSHOT

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


@Inherited
@Documented
@Target(value=METHOD)
@Retention(value=RUNTIME)
public @interface EventHandler

This annotation may only be used in subclasses of Composite that has been annotated with Templated, or in a super-class of said Composite types.

Declares a method in a Templated Composite widget as a handler for standard Event and DomEvent types fired by DataField widgets and data-field elements within the Composite component HTML template. Method handlers must accept a single argument of the type of event to be handled.

The following scenarios are supported by this annotation:

  1. GWT events on Widgets
  2. GWT events on DOM Elements
  3. Native DOM events on Elements

WARNING: Native GWT events cannot be used in conjunction with GWT standard events, since upon addition to the widget tree, GWT will override any Widget.sinkEvents(int) that may have been configured by Errai UI.

GWT events on Widgets

Example:

 @Templated
 public class WidgetHandlerComponent extends Composite
 {
    @Inject
    @DataField
    private Button button;
 
    @EventHandler("button")
    public void doSomethingC1(ClickEvent e)
    {
       // do something
    }
 }
 

GWT events on DOM Elements

Example:

 @Templated
 public class WidgetHandlerComponent extends Composite
 {
    @Inject
    @DataField
    private DivElement button;
 
    @EventHandler("button")
    public void doSomethingC1(ClickEvent e)
    {
       // do something
    }
 }
 

Native events on DOM Elements

This approach requires use of the SinkNative annotation, but does not require that target Element instances be referenced via DataField in the Templated Composite component; they may also target un-referenced data-field elements from the corresponding HTML template.

Example:

 @Templated
 public class QuickHandlerComponent extends Composite
 {
    @DataField
    private AnchorElement link = DOM.createAnchor().cast();
 
    @EventHandler("link")
    @SinkNative(Event.ONCLICK | Event.ONMOUSEOVER)
    public void doSomething(Event e)
    {
       // do something
    }
 
    @EventHandler("div")
    @SinkNative(Event.ONMOUSEOVER)
    public void doSomethingElse(Event e)
    {
       // do something with an element not otherwise referenced in our component
    }
 }
 

See also: SinkNative, Templated, DataField

Author:
Lincoln Baxter, III

Optional Element Summary
 String[] value
          Specifies the element for which the corresponding event type should be be handled.
 

value

public abstract String[] value
Specifies the element for which the corresponding event type should be be handled. The handled event type is defined by the handler method argument. By default, the event handler will be installed on the templated widget itself. To handle events that occur on a child widget or DOM node in the template, specify a value. This value must match either a DataField specified within the Templated Composite component (in the case of handling GWT event types,) or a data-field attribute in the corresponding HTML template (in the case of handling native DOM events.)

Default:
"this"

Errai 3.0.1-SNAPSHOT

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