Interface IMenuitem

All Superinterfaces:
IChildrenOfInputgroup<IMenuitem>, IChildrenOfMenupopup<IMenuitem>, IComponent<IMenuitem>, IDisable<IMenuitem>, IHtmlBasedComponent<IMenuitem>, ILabelElement<IMenuitem>, ILabelImageElement<IMenuitem>, IXulElement<IMenuitem>

Immutable Menuitem component

A single choice in a IMenupopup element. It acts much like a button but it is rendered on a menu.

Support @Action

Name Action Type
onCheck ActionData: CheckData
Denotes user has checked the item.
onUpload ActionData: FileData
Denotes user has uploaded a file to the component.
Author:
katherine
See Also:
  • Menuitem
  • Field Details

    • DEFAULT

      static final IMenuitem DEFAULT
      Constant for default attributes of this immutable component.
  • Method Details

    • getWidgetClass

      default String getWidgetClass()
      Returns the client widget class.

      Default: "zul.menu.Menuitem"

      Specified by:
      getWidgetClass in interface IComponent<IMenuitem>
    • getAutodisable

      @Nullable String getAutodisable()
      Returns a list of component IDs that shall be disabled when the user clicks this menuitem.

      Default: null

    • withAutodisable

      IMenuitem withAutodisable(@Nullable String autodisable)
      Returns a copy of this immutable component with the specified autodisable.

      Sets a list of component IDs that shall be disabled when the user clicks this menuitem.

      To represent the button itself, the developer can specify self. For example, .withAutodisable("self,cancel"); is the same as IMenuitem.ofId("ok").withAutodisable("ok,cancel"); that will disable both the ok and cancel menuitems when a user clicks it.

      The menuitem being disabled will be enabled automatically once the client receives a response from the server. In other words, the server doesn't notice if a menuitem is disabled with this method.

      However, if you prefer to enable them later manually, you can prefix with '+'. For example, IMenuitem.ofId("ok").withAutodisable("+self,+cancel");

      Then, you have to enable them manually such as

      if (something_happened){
        uiAgent.smartUpdate(Locator.ofId("ok"), new IMenuitem.Updater().disabled(false));
        uiAgent.smartUpdate(Locator.ofId("cancel"), new IMenuitem.Updater().disabled(false));
      
      Parameters:
      autodisable - Whether it is auto-disable.

      Default: null.

      Returns:
      A modified copy of the this object
    • getHref

      @Nullable String getHref()
      Returns the href that the browser shall jump to, if a user clicks this button.

      Default: null. If null, the button has no function unless you specify the onClick event listener.

      If it is not null, the onClick event won't be sent.

    • withHref

      IMenuitem withHref(@Nullable String href)
      Returns a copy of this immutable component with the specified href.

      Sets he href that the browser shall jump to, if a user clicks this menuitem.

      Parameters:
      href - The href that the browser shall jump to, if a user clicks this menuitem.

      Default: null.

      Returns:
      A modified copy of the this object
    • getTarget

      @Nullable String getTarget()
      Returns the target frame or window.

      Note: it is useful only if href (withHref(java.lang.String)) is specified (i.e., use the onClick listener).

      Default: null.

    • withTarget

      IMenuitem withTarget(@Nullable String target)
      Returns a copy of this immutable component with the specified target.

      Sets the target frame or window

      Parameters:
      target - The name of the frame or window to hyperlink.

      Default: null.

      Returns:
      A modified copy of the this object
    • getUpload

      @Nullable String getUpload()
      Returns non-null if this component is used for file upload, or null otherwise. Refer to withUpload(java.lang.String) for more details.

      Default: null

    • withUpload

      IMenuitem withUpload(@Nullable String upload)
      Returns a copy of this immutable component with the specified upload.

      Sets the JavaScript class at the client to handle the upload if this component is used for file upload.

      For example, the following example declares a button for file upload:

      IButton.of("Upload").withUpload("true").withAction(onUpload(this::doHandle));

      As shown above, after the file is uploaded, an instance of FileData is sent this handler.

      If you want to customize the handling of the file upload at the client, you can specify a JavaScript class when calling this method: withUpload("foo.Upload");

      Another options for the upload can be specified as follows:

      .withUpload("true,maxsize=-1,multiple=true,accept=audio/*|video/*|image/*,native");
      • maxsize: the maximal allowed upload size of the component, in kilobytes, or a negative value if no limit, if the maxsize is not specified, it will use Configuration.getMaxUploadSize()
      • native: treating the uploaded file(s) as binary, i.e., not to convert it to image, audio or text files.
      • multiple: treating the file chooser allows multiple files to upload, the setting only works with HTML5 supported browsers.
      • accept: specifies the types of files that the server accepts, the setting only works with HTML5 supported browsers.
      • suppressedErrors: specifies the suppressed uploading errors, separated by | (e.g. missing-required-component|illegal-upload) (since ZK 9.5.1).

      Note: if the options of the false or the customized handler (like foo.Upload) are not specified, the option of true is implicit by default.

      Parameters:
      upload - a JavaScript class to handle the file upload at the client, or "true" if the default class is used, or null or "false" to disable the file download (and then this button behaves like a normal button).

      Default: null.

      Returns:
      A modified copy of the this object
    • isCheckmark

      default boolean isCheckmark()
      Returns whether the check mark shall be displayed in front of each item.

      Default: false.

    • withCheckmark

      IMenuitem withCheckmark(boolean checkmark)
      Returns a copy of this immutable component with the specified checkmark.

      Sets whether the check mark shall be displayed in front of each item.

      Note: the checkbox can be checked only if isAutocheck() is true

      Parameters:
      checkmark - Whether the check mark shall be displayed in front of each item

      Default: false.

      Returns:
      A modified copy of the this object
    • isChecked

      default boolean isChecked()
      Returns whether it is checked.

      Default: false.

    • withChecked

      IMenuitem withChecked(boolean checked)
      Returns a copy of this immutable component with the specified checked.

      Sets whether it is checked.

      Note: the checkbox can be checked only if isAutocheck() is true

      Parameters:
      checked - Whether it is checked.

      Default: false.

      Returns:
      A modified copy of the this object
    • isAutocheck

      default boolean isAutocheck()
      Returns whether the menuitem check mark will update each time the menu item is selected.

      Default: false.

    • withAutocheck

      IMenuitem withAutocheck(boolean autocheck)
      Returns a copy of this immutable component with the specified autocheck.

      Sets whether the menuitem check mark will update each time the menu item is selected.

      Parameters:
      autocheck - Whether the menuitem check mark will update each time the menu item is selected.

      Default: false.

      Returns:
      A modified copy of the this object
    • of

      static IMenuitem of(String label)
      Returns the instance with the given label.
      Parameters:
      label - The label that the component
    • of

      static IMenuitem of(String label, String image)
      Returns the instance with the given label and image.
      Parameters:
      label - The label that the menuitem holds.
      image - The image that the menuitem holds.
    • ofImage

      static IMenuitem ofImage(String image)
      Returns the instance with the given image.
      Parameters:
      image - The image that the menuitem holds.
    • ofId

      static IMenuitem ofId(String id)
      Returns the instance with the given id.
      Parameters:
      id - The id to identify this component