Class JavaScriptUtils


  • public class JavaScriptUtils
    extends Object
    Provide some helpers to write javascript related tags to the response object.
    Author:
    Juergen Donnerstag
    • Constructor Detail

      • JavaScriptUtils

        public JavaScriptUtils​(org.apache.wicket.request.Response response,
                               String id)
        Construct.
        Parameters:
        response - The response object
        id -
      • JavaScriptUtils

        public JavaScriptUtils​(org.apache.wicket.request.Response response)
        Constructor without id for backward compatibility
        Parameters:
        response - The response object
    • Method Detail

      • escapeQuotes

        public static CharSequence escapeQuotes​(CharSequence input)
        Escape single and double quotes so that they can be part of e.g. an alert call. Note: JSON values need to escape only the double quote, so this method wont help.
        Parameters:
        input - the JavaScript which needs to be escaped
        Returns:
        Escaped version of the input
      • writeJavaScriptUrl

        @Deprecated
        public static void writeJavaScriptUrl​(org.apache.wicket.request.Response response,
                                              CharSequence url,
                                              String id,
                                              boolean defer,
                                              String charset)
        Deprecated.
        Write a reference to a javascript file to the response object
        Parameters:
        response - The HTTP response
        url - The javascript file URL
        id - Unique identifier of element
        defer - specifies that the execution of a script should be deferred (delayed) until after the page has been loaded.
        charset - a non null value specifies the charset attribute of the script tag
      • writeJavaScriptUrl

        @Deprecated
        public static void writeJavaScriptUrl​(org.apache.wicket.request.Response response,
                                              CharSequence url,
                                              String id,
                                              boolean defer,
                                              String charset,
                                              boolean async)
        Deprecated.
        Write a reference to a javascript file to the response object
        Parameters:
        response - The HTTP response
        url - The javascript file URL
        id - Unique identifier of element
        defer - specifies that the execution of a script should be deferred (delayed) until after the page has been loaded.
        charset - a non null value specifies the charset attribute of the script tag
        async - specifies that the script can be loaded asynchronously by the browser
      • writeScript

        public static void writeScript​(org.apache.wicket.request.Response response,
                                       org.apache.wicket.util.value.AttributeMap attributes)
        Write a reference to a javascript file to the response object
        Parameters:
        response - The HTTP response
        attributes - Extra tag attributes
      • writeInlineScript

        public static void writeInlineScript​(org.apache.wicket.request.Response response,
                                             CharSequence text,
                                             org.apache.wicket.util.value.AttributeMap attributes)
        Write the simple text to the response object surrounded by a script tag.
        Parameters:
        response - The HTTP: response
        text - The text to added in between the script tags
        attributes - Extra tag attributes
      • writeJavaScript

        public static void writeJavaScript​(org.apache.wicket.request.Response response,
                                           CharSequence text)
        Write the simple text to the response object surrounded by a script tag.
        Parameters:
        response - The HTTP: response
        text - The text to added in between the script tags
      • writeOpenTag

        public static void writeOpenTag​(org.apache.wicket.request.Response response,
                                        org.apache.wicket.util.value.AttributeMap attributes)
        Write open script tag for inline script. Content is prefixed with SCRIPT_CONTENT_PREFIX.
        Parameters:
        response - the response to write to
        attributes - Tag attributes map
      • writeCloseTag

        public static void writeCloseTag​(org.apache.wicket.request.Response response)
        Write close script tag for inline script. The close tag is prefixed with SCRIPT_CONTENT_SUFFIX
        Parameters:
        response - the response to write to
      • write

        public void write​(CharSequence script)
        Parameters:
        script -
        See Also:
        Response.write(java.lang.CharSequence)
      • println

        public void println​(CharSequence script)
        Parameters:
        script -
        See Also:
        Response.write(CharSequence)