Search in sources :

Example 1 with PackageTextTemplate

use of org.apache.wicket.util.template.PackageTextTemplate in project wicket-dashboard by decebals.

the class DashboardColumnPanel method renderHead.

@Override
public void renderHead(IHeaderResponse response) {
    super.renderHead(response);
    CharSequence script = sortableAjaxBehavior.getCallbackFunctionBody();
    Map<String, String> vars = new HashMap<String, String>();
    vars.put("component", get("columnContainer").getMarkupId());
    vars.put("stopBehavior", script.toString());
    PackageTextTemplate template = new PackageTextTemplate(DashboardColumnPanel.class, "res/sort-behavior.template.js");
    template.interpolate(vars);
    response.render(OnDomReadyHeaderItem.forScript(template.getString()));
}
Also used : HashMap(java.util.HashMap) PackageTextTemplate(org.apache.wicket.util.template.PackageTextTemplate)

Example 2 with PackageTextTemplate

use of org.apache.wicket.util.template.PackageTextTemplate in project wicket by apache.

the class BaseWebSocketBehavior method renderHead.

@Override
public void renderHead(Component component, IHeaderResponse response) {
    super.renderHead(component, response);
    response.render(JavaScriptHeaderItem.forReference(WicketWebSocketJQueryResourceReference.get()));
    PackageTextTemplate webSocketSetupTemplate = new PackageTextTemplate(WicketWebSocketJQueryResourceReference.class, "res/js/wicket-websocket-setup.js.tmpl");
    Map<String, Object> variables = Generics.newHashMap();
    // set falsy JS values for the non-used parameter
    if (Strings.isEmpty(resourceName)) {
        int pageId = component.getPage().getPageId();
        variables.put("pageId", pageId);
        variables.put("resourceName", "");
    } else {
        variables.put("resourceName", resourceName);
        variables.put("pageId", false);
    }
    WebSocketSettings webSocketSettings = WebSocketSettings.Holder.get(component.getApplication());
    CharSequence baseUrl = getBaseUrl(webSocketSettings);
    Args.notNull(baseUrl, "baseUrl");
    variables.put("baseUrl", baseUrl);
    Integer port = getPort(webSocketSettings);
    variables.put("port", port);
    Integer securePort = getSecurePort(webSocketSettings);
    variables.put("securePort", securePort);
    CharSequence contextPath = getContextPath(webSocketSettings);
    Args.notNull(contextPath, "contextPath");
    variables.put("contextPath", contextPath);
    // preserve the application name for JSR356 based impl
    variables.put("applicationName", component.getApplication().getName());
    CharSequence filterPrefix = getFilterPrefix(webSocketSettings);
    Args.notNull(filterPrefix, "filterPrefix");
    variables.put("filterPrefix", filterPrefix);
    final CharSequence sessionId = getSessionId(component);
    variables.put("sessionId", sessionId);
    String webSocketSetupScript = webSocketSetupTemplate.asString(variables);
    response.render(OnDomReadyHeaderItem.forScript(webSocketSetupScript));
}
Also used : PackageTextTemplate(org.apache.wicket.util.template.PackageTextTemplate) WebSocketSettings(org.apache.wicket.protocol.ws.WebSocketSettings)

Aggregations

PackageTextTemplate (org.apache.wicket.util.template.PackageTextTemplate)2 HashMap (java.util.HashMap)1 WebSocketSettings (org.apache.wicket.protocol.ws.WebSocketSettings)1