Class MenuItemWidget

java.lang.Object
org.apache.juneau.rest.widget.Widget
org.apache.juneau.rest.widget.MenuItemWidget
All Implemented Interfaces:
HtmlWidget
Direct Known Subclasses:
ContentTypeMenuItem, QueryMenuItem, ThemeMenuItem

public abstract class MenuItemWidget extends Widget
A subclass of widgets for rendering menu items with drop-down windows.
See Also:
  • Constructor Details

  • Method Details

    • getScript

      Returns the Javascript needed for the show and hide actions of the menu item.
      Overrides:
      getScript in class Widget
      Parameters:
      req - The HTTP request object.
      res - The current HTTP response.
      Returns:
      The Javascript needed by this widget.
    • getBeforeShowScript

      Optional Javascript to execute immediately before a menu item is shown.

      For example, the following shows how the method could be used to make an AJAX call back to the REST interface to populate a SELECT element in the contents of the popup dialog:

      @Override public String getBeforeShowScript(RestRequest req) { return "" + "\n var xhr = new XMLHttpRequest();" + "\n xhr.open('GET', '/petstore/pet?s=status=AVAILABLE&v=id,name', true);" + "\n xhr.setRequestHeader('Accept', 'application/json');" + "\n xhr.onload = function() {" + "\n var pets = JSON.parse(xhr.responseText);" + "\n var select = document.getElementById('addPet_names');" + "\n select.innerHTML = '';" + "\n for (var i in pets) {" + "\n var pet = pets[i];" + "\n var opt = document.createElement('option');" + "\n opt.value = pet.id;" + "\n opt.innerHTML = pet.name;" + "\n select.appendChild(opt);" + "\n }" + "\n }" + "\n xhr.send();" ; }

      Note that it's often easier (and cleaner) to use the Widget.loadScript(RestRequest,String) method and read the Javascript from your classpath:

      @Override public String getBeforeShowScript(RestRequest req) throws Exception { return loadScript("AddOrderMenuItem_beforeShow.js"); }

      Parameters:
      req - The HTTP request object.
      res - The HTTP response object.
      Returns:
      Javascript code to execute, or null if there isn't any.
    • getAfterShowScript

      Optional Javascript to execute immediately after a menu item is shown.

      Same as getBeforeShowScript(RestRequest,RestResponse) except this Javascript gets executed after the popup dialog has become visible.

      Parameters:
      req - The HTTP request object.
      res - The HTTP response object.
      Returns:
      Javascript code to execute, or null if there isn't any.
    • getStyle

      Defines a "menu-item" class that needs to be used on the outer element of the HTML returned by the getHtml(RestRequest,RestResponse) method.
      Overrides:
      getStyle in class Widget
      Parameters:
      req - The HTTP request object.
      res - The current HTTP response.
      Returns:
      The CSS styles needed by this widget.
    • getHtml

      public String getHtml(RestRequest req, RestResponse res)
      Description copied from class: Widget
      Resolves the HTML content for this widget.

      A returned value of null will cause nothing to be added to the page.

      Overrides:
      getHtml in class Widget
      Parameters:
      req - The HTTP request object.
      res - The current HTTP response.
      Returns:
      The HTML content of this widget.
    • getLabel

      public abstract String getLabel(RestRequest req, RestResponse res)
      The label for the menu item as it's rendered in the menu bar.
      Parameters:
      req - The HTTP request object.
      res - The HTTP response object.
      Returns:
      The menu item label.
    • getContent

      public abstract Object getContent(RestRequest req, RestResponse res)
      The content of the popup.
      Parameters:
      req - The HTTP request object.
      res - The HTTP response object.
      Returns:
      The content of the popup.
      Can be any of the following types: