Class MenuItemWidget
- All Implemented Interfaces:
HtmlWidget
- Direct Known Subclasses:
ContentTypeMenuItem
,QueryMenuItem
,ThemeMenuItem
See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiongetAfterShowScript
(RestRequest req, RestResponse res) Optional Javascript to execute immediately after a menu item is shown.getBeforeShowScript
(RestRequest req, RestResponse res) Optional Javascript to execute immediately before a menu item is shown.abstract Object
getContent
(RestRequest req, RestResponse res) The content of the popup.getHtml
(RestRequest req, RestResponse res) Resolves the HTML content for this widget.abstract String
getLabel
(RestRequest req, RestResponse res) The label for the menu item as it's rendered in the menu bar.getScript
(RestRequest req, RestResponse res) Returns the Javascript needed for the show and hide actions of the menu item.getStyle
(RestRequest req, RestResponse res) Defines a"menu-item" class that needs to be used on the outer element of the HTML returned by thegetHtml(RestRequest,RestResponse)
method.Methods inherited from class org.apache.juneau.rest.widget.Widget
getFileFinder, getHtml, getName, getScript, getStyle, loadHtml, loadHtmlWithVars, loadScript, loadScriptWithVars, loadStyle, loadStyleWithVars
-
Constructor Details
-
MenuItemWidget
public MenuItemWidget()
-
-
Method Details
-
getScript
Returns the Javascript needed for the show and hide actions of the menu item. -
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(RestRequestreq ) {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(RestRequestreq )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 thegetHtml(RestRequest,RestResponse)
method. -
getHtml
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. -
getLabel
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
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:Reader
- Serialized directly to the output.CharSequence
- Serialized directly to the output.- Other - Serialized as HTML using
HtmlSerializer.DEFAULT
.
Note that this includes any of theorg.apache.juneau.dto.html5
beans.
-