Class JsStatement

  • All Implemented Interfaces:
    java.io.Serializable

    public class JsStatement
    extends java.lang.Object
    implements java.io.Serializable
    $Id: JsStatement.java 1714M 2012-01-17 08:35:15Z (local) $

    A JsStatement defines a whole executable JavaScript statement. The generator eases "jQuery oriented" code, but you can still use another JavaScript coding style with the append(CharSequence) method.

    To get a valid instance and to ease JavaScript and Wicket integration, you should use the JsQuery class (example below). This class will initialize a JsStatement and contribute to a WebPage.

    The JavaScript generating by a JsStatement is jQuery oriented. Example of generated string:

    $(".aClassName").each(function() {alert('foo');});

    To generate the script above, you can write this:

    new JsQuery().$().each(JsScope.quickScope("alert('foo')"));

    Any JsStatement should be returned by a JsQuery within the $ methods.

    Since:
    0.7
    Author:
    Lionel Armanet
    See Also:
    JsQuery, JsScope, Serialized Form
    • Constructor Detail

      • JsStatement

        public JsStatement()
        Creates a new JsStatement.
    • Method Detail

      • $

        public JsStatement $()
        Appends the jQuery's $ function to the current JsStatement. So, we can call some special jquery fonction, like $.browser ...
        Returns:
        JsStatement this instance.
      • $

        public JsStatement $​(org.apache.wicket.Component context,
                             java.lang.String selector)
        Appends the jQuery's $ function to the current JsStatement. If context is not null, the generated JavaScript code will be:

        $("#component.getMarkupId selector")

        If context is null, the generated JavaScript code will be:

        $("selector")

        Returns:
        JsStatement this instance.
      • addClass

        public JsStatement addClass​(java.lang.String className)
        Binds the addClass statement.
      • after

        public JsStatement after​(java.lang.CharSequence html)
        Binds the after statement.
      • append

        public JsStatement append​(java.lang.CharSequence charSequence)
        Appends the given CharSequence to this statement.
        Returns:
        JsStatement this instance.
      • attr

        public JsStatement attr​(java.lang.String key,
                                JsScope computedValue)
        Binds the attr statement.
      • attr

        public JsStatement attr​(java.lang.String key,
                                java.lang.String value)
        Binds the attr statement.
      • before

        public JsStatement before​(java.lang.CharSequence html)
        Binds the before statement.
      • chain

        public JsStatement chain​(java.lang.CharSequence statementLabel,
                                 java.lang.CharSequence... statementArgs)
        Chains a function call to this JsStatement. This will append statementLabel(statementArgs) to this JsStatement.
        Parameters:
        statementLabel - the statement label to append.
        statementArgs - the statement args.
        Returns:
        JsStatement this instance.
      • css

        public JsStatement css​(java.lang.String name,
                               java.lang.String value)
        Binds the css statement.
      • document

        public JsStatement document()
        Appends $(document) to the statement.
        Returns:
        JsStatement this instance.
      • each

        public JsStatement each​(JsScope scope)
        Appends the each jQuery statement.
        Parameters:
        scope - the JsScope to execute within every matched element.
      • getStatement

        public java.lang.StringBuilder getStatement()
        Returns:
        the statement of the JsStatement
      • html

        public JsStatement html​(java.lang.CharSequence htmlContents)
        Binds the html statement.
      • insertAfter

        public JsStatement insertAfter​(java.lang.String expression)
        Binds the insertAfter statement.
      • insertBefore

        public JsStatement insertBefore​(java.lang.String expression)
        Binds the insertBefore statement.
      • ready

        public JsStatement ready​(JsScope scope)
        Appends the ready jQuery statement.
        Parameters:
        scope - the JsScope to execute when jQuery is ready.
      • removeAttr

        public JsStatement removeAttr​(java.lang.String key)
        Binds the removeAttr statement.
      • removeClass

        public JsStatement removeClass​(java.lang.String className)
        Binds the removeClass statement.
      • render

        public java.lang.CharSequence render()
        Renders this statement.
        Returns:
        the renderable JavaScript statement as a CharSequence.
      • render

        public java.lang.CharSequence render​(boolean semicolon)
        Renders this statement.
        Parameters:
        semicolon - If true, a semicolon is automatically added
        Returns:
        the renderable JavaScript statement as a CharSequence.
      • self

        public JsStatement self()
        Appends the this keyword to this statement.
        Returns:
        JsStatement this instance.
      • toggleClass

        public JsStatement toggleClass​(java.lang.String className)
        Binds the toggleClass statement.