List of usage examples for org.apache.wicket.ajax.attributes AjaxRequestAttributes getExtraParameters
public Map<String, Object> getExtraParameters()
From source file:com.comcast.cdn.traffic_control.traffic_monitor.wicket.behaviors.AbstractMultiAjaxBehavior.java
License:Apache License
private void appendSpecial(final JSONObject attributesJson, final AjaxRequestAttributes attributes) throws JSONException { final Method method = attributes.getMethod(); if (Method.POST == method) { attributesJson.put("m", method); }/*from www. jav a2 s . co m*/ if (component instanceof Page == false) { final String componentId = component.getMarkupId(); attributesJson.put("c", componentId); } final JSONArray extraParameters = JsonUtils.asArray(attributes.getExtraParameters()); if (extraParameters.length() > 0) { attributesJson.put("ep", extraParameters); } final String[] eventNames = attributes.getEventNames(); if (eventNames.length == 1) { attributesJson.put("e", eventNames[0]); } else { for (String eventName : eventNames) { attributesJson.append("e", eventName); } } final AjaxChannel channel = attributes.getChannel(); if (channel != null) { attributesJson.put("ch", channel); } final Duration requestTimeout = attributes.getRequestTimeout(); if (requestTimeout != null) { attributesJson.put("rt", requestTimeout.getMilliseconds()); } final String dataType = attributes.getDataType(); if (AjaxRequestAttributes.XML_DATA_TYPE.equals(dataType) == false) { attributesJson.put("dt", dataType); } }
From source file:com.comcast.cdn.traffic_control.traffic_monitor.wicket.behaviors.AbstractMultiAjaxBehavior.java
License:Apache License
/** * Generates the body the/*from ww w . ja v a 2s .c om*/ * {@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:com.googlecode.wickedcharts.wicket6.JavaScriptExpressionSendingAjaxBehavior.java
License:Apache License
@Override protected void updateAjaxAttributes(AjaxRequestAttributes attributes) { super.updateAjaxAttributes(attributes); for (String parameterName : this.javascriptExpressions.keySet()) { attributes.getExtraParameters().put(parameterName, this.javascriptExpressions.get(parameterName)); }/*from w ww .j av a2 s . c om*/ }
From source file:org.apache.syncope.client.console.panels.RuntimePanel.java
License:Apache License
public void startPolling(final int seconds) { AbstractAjaxTimerBehavior timer = new AbstractAjaxTimerBehavior(Duration.seconds(seconds)) { private static final long serialVersionUID = 1L; @Override/* w w w . ja v a 2 s .c om*/ protected void onTimer(AjaxRequestTarget target) { target.add(refresh()); } @Override protected void updateAjaxAttributes(AjaxRequestAttributes attributes) { super.updateAjaxAttributes(attributes); attributes.getExtraParameters().put("pollingTimeout", "true"); } }; panel.setTimer(timer); }
From source file:org.hippoecm.frontend.plugins.richtext.view.PreviewLinksBehavior.java
License:Apache License
@Override public String internalLink(String link) { final AjaxRequestAttributes attributes = getAttributes(); final Charset charset = RequestCycle.get().getRequest().getCharset(); if (linkExists(link)) { if (encode) { link = UrlEncoder.QUERY_INSTANCE.encode(link, charset); }//from w w w . ja v a 2 s . c o m attributes.getExtraParameters().put("link", link); CharSequence asString = renderAjaxAttributes(getComponent(), attributes); return "href=\"#\" onclick='" + JS_PREVENT_DEFAULT + JS_STOP_EVENT + "Wicket.Ajax.get(" + asString + ");'"; } else { String message = new ClassResourceModel("brokenlink-alert", PreviewLinksBehavior.class).getObject(); return "class=\"brokenlink\" href=\"#\" onclick=\"alert('" + message + "');return false;\""; } }
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}./* ww w . j a va2 s .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; }
From source file:org.wicketstuff.js.ext.ExtMessageBoxCallback.java
License:Apache License
@Override protected void updateAjaxAttributes(final AjaxRequestAttributes attributes) { attributes.setMethod(AjaxRequestAttributes.Method.POST); attributes.getExtraParameters().put(POST_PARAM_BTN, "btn"); attributes.getExtraParameters().put(POST_PARAM_TEXT, "btn"); }
From source file:sk.drunkenpanda.leaflet.behaviors.LeafletAjaxBehavior.java
License:Apache License
@Override protected void updateAjaxAttributes(AjaxRequestAttributes attributes) { super.updateAjaxAttributes(attributes); for (java.util.Map.Entry<String, String> entry : this.parameters.entrySet()) { String parameterName = entry.getKey(); String parameterValue = entry.getValue(); attributes.getExtraParameters().put(parameterName, parameterValue); }/*w w w .j ava 2 s . c om*/ }
From source file:sk.drunkenpanda.leaflet.behaviors.LeafletAjaxBehaviorTest.java
License:Apache License
@Test public void testStoresAttributesInAjaxRequest() { ImmutableMap<String, String> attributes = ImmutableMap.of("test1", "A", "test2", "B", "test3", "C"); TestAjaxBehavior behavior = new TestAjaxBehavior(attributes); final AjaxRequestAttributes requestAttributes = new AjaxRequestAttributes(); behavior.updateAjaxAttributes(requestAttributes); for (java.util.Map.Entry<String, String> entry : attributes.entrySet()) { Object actual = requestAttributes.getExtraParameters().get(entry.getKey()); assertThat(actual).isNotNull();/*from w ww. ja v a 2 s .com*/ assertThat(actual).isEqualTo(entry.getValue()); } }