Example usage for org.apache.wicket.ajax.attributes CallbackParameter getAjaxParameterCode

List of usage examples for org.apache.wicket.ajax.attributes CallbackParameter getAjaxParameterCode

Introduction

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

Prototype

public String getAjaxParameterCode() 

Source Link

Usage

From source file:com.comcast.cdn.traffic_control.traffic_monitor.wicket.behaviors.AbstractMultiAjaxBehavior.java

License:Apache License

/**
 * Generates the body the//  w  w  w  .  ja  v a  2s .co m
 * {@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
 * @return The body of the
 *         {@linkplain #getCallbackFunction(CallbackParameter...) callback
 *         function}.
 */
public CharSequence getCallbackFunctionBody(final CallbackParameter... extraParameters) {
    final AjaxRequestAttributes attributes = getAttributes();
    final CharSequence attrsJson = renderAjaxAttributes(getComponent(), attributes);
    final 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.ep = params;\n");
    } else {
        sb.append("attrs.ep = Wicket.merge(attrs.ep, params);\n");
    }
    sb.append("Wicket.Ajax.ajax(attrs);\n");
    return sb;
}

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}.//from w  w w  . j  a va2  s  .co  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;
}