Annotation Type Action


  • @Target({TYPE_USE,METHOD})
    @Retention(RUNTIME)
    public @interface Action
    Annotation for mapping client widget events onto methods in StatelessComposer or StatelessRichlet classes with flexible method signatures.
    Author:
    jumperchen
    • Required Element Summary

      Required Elements 
      Modifier and Type Required Element Description
      java.lang.String[] type
      The client widget events, i.e.
    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element Description
      java.lang.String from
      Finding the queried target(s) of matching the from() with the given type() to bind to this action.
      • from

        java.lang.String from
        Finding the queried target(s) of matching the from() with the given type() 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 with from().

        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 use IComponent.withAction(ActionHandler) or IComponent.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() {}
         
        The above example is the same as this by specifying an individual handler.
         @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 named button and ITextbox is named textbox.

        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() and doButtonClick() 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:
        ""