Annotation Type Action
-
@Target({TYPE_USE,METHOD}) @Retention(RUNTIME) public @interface Action
Annotation for mapping client widget events onto methods inStatelessComposer
orStatelessRichlet
classes with flexible method signatures.- Author:
- jumperchen
-
-
Element Detail
-
type
java.lang.String[] type
The client widget events, i.e.Events.ON_CLICK
-
-
-
from
java.lang.String from
Finding the queried target(s) of matching thefrom()
with the giventype()
to bind to this action.Default:
""
an empty string, meaning no any target is bound to this action, unless specifying it into an individual action handler.
For example,
@
RichletMapping
("/click") public IComponent clickAction() { return IButton.of("doClick").withAction(this::doClick); } @Action(type = Events.ON_CLICK) public void doClick() {}Performance tip: It's recommended to use an individual action handler with
IComponent.withAction(ActionHandler)
instead of the query selector withfrom()
.Note: the annotation binding is only available when the page is at initial phase, all the other dynamically added components won't take effect. In other words, all components are created after the page initiated will not bind with the
Action
annotation, please useIComponent.withAction(ActionHandler)
orIComponent.withActions(ActionHandler...)
instead.The selector expression
ID
The ZK
ID
selector, which starts with#
, similar with CSS selector.
For example,
@
RichletMapping
("/button/click") public IComponent clickAction() { return IButton.ofId("btn"); } @Action(from = "#btn", type = Events.ON_CLICK) public void doButtonClick() {}@
RichletMapping
("/button/click") public IComponent clickAction() { return IButton.ofId("btn").withAction(this::doButtonClick); } @Action(type = Events.ON_CLICK) public void doButtonClick() {}Component Widget Name
The widget name of ZK component at client, i.e.
IButton
is namedbutton
andITextbox
is namedtextbox
.
For example,
@
RichletMapping
("/allButtons/click") public IComponent clickAction() { return IDiv.of(IButton.of("button 1"), IButton.of("button 2"), ...); } @Action(from = "button", type = Events.ON_CLICK) public void doAllButtonsClick(@ActionVariable
(targetId=ActionTarget.SELF, field="label") String buttonLabel) {}Note: the action target is a type of ZK client widget, which extends from zk.Widget, not the DOM element in this case. Be aware of that, if multiple actions are bound to a single target with the same
type()
, then each action handler will be invoked in a non-deterministic order. As shown above,doAllButtonsClick()
anddoButtonClick()
are all bound to a button"#btn"
, when the button is clicked by a user, both action handlers are invoked in a unknown order. Even if the case with a specific action.withAction(this::doButtonClick)
, the invoked order cannot be deterministic.- See Also:
ActionVariable
- Default:
- ""
-
-