Example usage for org.apache.wicket.ajax.attributes AjaxAttributeName EXTRA_PARAMETERS

List of usage examples for org.apache.wicket.ajax.attributes AjaxAttributeName EXTRA_PARAMETERS

Introduction

In this page you can find the example usage for org.apache.wicket.ajax.attributes AjaxAttributeName EXTRA_PARAMETERS.

Prototype

AjaxAttributeName EXTRA_PARAMETERS

To view the source code for org.apache.wicket.ajax.attributes AjaxAttributeName EXTRA_PARAMETERS.

Click Source Link

Document

extra parameters (ep)

Usage

From source file:org.wicketstuff.js.ext.ExtEventAjaxBehavior.java

License:Apache License

/**
 * FIXME: code copy & pasted from wicket; the Component should not be rendered as attribute
 * as this will trigger a precondition check (whether an element with the markupId exists)
 *
 * Generates the body the {@linkplain #getCallbackFunction(CallbackParameter...) callback
 * function}. To embed this code directly into a piece of javascript, make sure any context
 * parameters are available as local variables, global variables or within the closure.
 *
 * @param extraParameters parameters for the callback
 * @return The body of the {@linkplain #getCallbackFunction(CallbackParameter...) callback
 *         function}./*www .j  a v a2s .  c  o  m*/
 */
public CharSequence getCallbackFunctionBody(CallbackParameter... extraParameters) {
    AjaxRequestAttributes attributes = getAttributes();
    attributes.setEventNames();
    CharSequence attrsJson = renderAjaxAttributes(getComponent().getPage(), attributes);
    StringBuilder sb = new StringBuilder();
    sb.append("var attrs = ");
    sb.append(attrsJson);
    sb.append(";\n");
    sb.append("var params = {");
    boolean first = true;
    for (CallbackParameter curExtraParameter : extraParameters) {
        if (curExtraParameter.getAjaxParameterName() != null) {
            if (!first)
                sb.append(',');
            else
                first = false;
            sb.append('\'').append(curExtraParameter.getAjaxParameterName()).append("': ")
                    .append(curExtraParameter.getAjaxParameterCode());
        }
    }
    sb.append("};\n");
    if (attributes.getExtraParameters().isEmpty())
        sb.append("attrs." + AjaxAttributeName.EXTRA_PARAMETERS + " = params;\n");
    else
        sb.append("attrs." + AjaxAttributeName.EXTRA_PARAMETERS + " = Wicket.merge(attrs."
                + AjaxAttributeName.EXTRA_PARAMETERS + ", params);\n");
    sb.append("Wicket.Ajax.ajax(attrs);\n");
    return sb;
}