Example usage for org.apache.wicket.ajax.attributes AjaxRequestAttributes getDynamicExtraParameters

List of usage examples for org.apache.wicket.ajax.attributes AjaxRequestAttributes getDynamicExtraParameters

Introduction

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

Prototype

public List<CharSequence> getDynamicExtraParameters() 

Source Link

Document

Array of JavaScript functions that produce additional URL arguments.

Usage

From source file:com.axway.ats.testexplorer.pages.BasePage.java

License:Apache License

public BasePage(PageParameters parameters) {

    super(parameters);

    LOG = Logger.getLogger(this.getClass());

    add(new Label("page_title", "Axway ATS Test Explorer - " + getPageName()));

    // check DB connection and sets the current DB Name
    getTESession().getDbReadConnection();

    WebMarkupContainer topRightContent = new WebMarkupContainer("topRightContent");
    add(topRightContent);/*from   w  w  w  .  jav a 2 s . co m*/

    String dbName = getTESession().getDbName();
    if (dbName == null || "".equals(dbName)) {
        topRightContent.add(new Label("dbName", "").setVisible(false));
        topRightContent.add(new Label("machinesLink", "").setVisible(false));
        topRightContent.add(new Label("runCopyLink", runCopyLinkModel).setVisible(false));
        topRightContent.add(new Label("testcasesCopyLink", testcasesCopyLinkModel).setVisible(false));
        topRightContent.add(new Label("representationLink", representationLinkModel).setVisible(false));
    } else {
        String dbNameAndVersion = dbName;
        String dbVersion = getTESession().getDbVersion();
        if (dbVersion != null) {
            dbNameAndVersion = dbNameAndVersion + ", v" + dbVersion;
        }
        topRightContent.add(new Label("dbName",
                "<div class=\"dbName\"><span style=\"color:#C8D5DF;\">Exploring database:</span>&nbsp; "
                        + dbNameAndVersion + "</div>").setEscapeModelStrings(false));
        topRightContent.add(new Label("machinesLink",
                "<a href=\"machines?dbname=" + dbName + "\" class=\"machinesLink\" target=\"_blank\"></a>")
                        .setEscapeModelStrings(false));
        runCopyLinkModel.setObject(
                "<a href=\"runCopy?dbname=" + dbName + "\" class=\"runCopyLink\" target=\"_blank\"></a>");
        topRightContent.add(new Label("runCopyLink", runCopyLinkModel).setEscapeModelStrings(false));

        testcasesCopyLinkModel.setObject("<a href=\"testcasesCopy?dbname=" + dbName
                + "\" class=\"testcasesCopyLink\" target=\"_blank\"></a>");
        topRightContent.add(getTestcasesCopyButton());

        representationLinkModel.setObject(createRepresentationLinkModelObject());

        topRightContent
                .add(new Label("representationLink", representationLinkModel).setEscapeModelStrings(false));

    }

    itemsCountLabel = new Label("itemsCount", new Model<Integer>() {

        private static final long serialVersionUID = 1L;

        @Override
        public Integer getObject() {

            return getTESession().getCompareContainer().size();
        }
    });
    itemsCountLabel.setOutputMarkupId(true);
    topRightContent.setVisible(!(this instanceof WelcomePage));
    topRightContent.add(itemsCountLabel);

    FeedbackPanel feedbackPanel = new FeedbackPanel("feedback");
    feedbackPanel.setOutputMarkupId(true);
    add(feedbackPanel);

    // add navigation panel
    add(new ListView<PagePojo>("navigation_links", navigationList) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(ListItem<PagePojo> item) {

            final PagePojo pp = item.getModelObject();

            if (pp.pageSuffix != null && !pp.pageName.endsWith("</span>")) {
                pp.pageName = pp.pageName + " <span class=\"locationName\">[" + pp.pageSuffix + "]</span>";
            }

            item.add(new Link<Object>("navigation_link") {

                private static final long serialVersionUID = 1L;

                @Override
                protected CharSequence getURL() {

                    // generate Bookmarkable link url
                    return urlFor(pp.pageClass, pp.parameters);
                }

                @Override
                public void onClick() {

                    // This link acts like Bookmarkable link and don't have a click handler.
                }
            }.add(new Label("navigation_link_name", pp.pageName).setEscapeModelStrings(false)));
        }
    });
    add(new Label("navigation_current_page_name", getPageName()));
    add(getNavigationSuffixComponent());
    add(getTestcaseNavigationButtons());

    currentTestDetails();

    // add child page
    TransparentWebMarkupContainer pageWrapper = new TransparentWebMarkupContainer("page_wrapper");
    add(pageWrapper);

    if (TestExplorerUtils.extractPageParameter(parameters, "hacks") != null) {
        showTestcaseStatusChangeButtons = true;
    }

    add(timeOffsetField);
    add(dayLightSavingOnField);

    // AJAX handler for obtaining browser's time offset from UTC and current browser timestamp
    add(new AbstractDefaultAjaxBehavior() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void respond(AjaxRequestTarget target) {

            IRequestParameters request = RequestCycle.get().getRequest().getRequestParameters();
            int timeOffset = request.getParameterValue("timeOffset").toInt();
            TestExplorerSession teSession = (TestExplorerSession) Session.get();
            teSession.setTimeOffset(timeOffset);
            teSession.setDayLightSavingOn(request.getParameterValue("dayLightSavingOn").toBoolean());
        }

        @Override
        protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {

            super.updateAjaxAttributes(attributes);
            attributes.getDynamicExtraParameters().add("return {'timeOffset': $('#timeOffset').val(), "
                    + "'dayLightSavingOn': $('#dayLightSavingOn').val() }");
        }

        @Override
        public void renderHead(Component component, IHeaderResponse response) {

            // Date.prototype.getTimezoneOffset() returns negative value if the local time is ahead of UTC,
            // so we invert the result, before sending it to Wicket
            String getTimeOffsetScript = ";var timeOffset = $('#timeOffset');timeOffset.val(new Date().getTimezoneOffset()*60*1000*-1);"
                    + ";var dayLightSavingOn = $('#dayLightSavingOn');dayLightSavingOn.val(isDayLightSavingOn());";
            response.render(OnLoadHeaderItem.forScript(getCallbackScript().toString()));
            response.render(OnLoadHeaderItem.forScript(getTimeOffsetScript));
        }

    });

}

From source file:com.axway.ats.testexplorer.pages.reports.testcase.TestcaseReportPage.java

License:Apache License

public TestcaseReportPage(PageParameters parameters) throws IOException {

    super(parameters);

    reportHomeFolder = getAbsolutePathOfClass();
    reportHomeFolder = IoUtils.normalizeDirPath(reportHomeFolder);
    if (OperatingSystemType.getCurrentOsType().isWindows()
            && reportHomeFolder.startsWith(SYSTEM_FILE_SEPARATOR)) {

        reportHomeFolder = reportHomeFolder.substring(1);
    }/*from  w w w  .  j  a  v a2 s.co  m*/
    reportHomeFolder = reportHomeFolder.substring(0, reportHomeFolder.lastIndexOf(SYSTEM_FILE_SEPARATOR));
    // the current folder path is encoded (e.g. ' ' = '%20'). We need to decode it
    reportHomeFolder = URLDecoder.decode(reportHomeFolder, "UTF-8");

    add(timeOffsetField);
    add(dayLightSavingOnField);

    // AJAX handler for obtaining browser's time offset from UTC
    add(new AbstractDefaultAjaxBehavior() {

        private static final long serialVersionUID = 1L;

        @Override
        protected void respond(AjaxRequestTarget target) {

            IRequestParameters request = RequestCycle.get().getRequest().getRequestParameters();
            int timeOffset = request.getParameterValue("timeOffset").toInt();
            TestExplorerSession teSession = (TestExplorerSession) Session.get();
            teSession.setTimeOffset(timeOffset);
            teSession.setDayLightSavingOn(request.getParameterValue("dayLightSavingOn").toBoolean());
        }

        @Override
        protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {

            super.updateAjaxAttributes(attributes);
            attributes.getDynamicExtraParameters().add("return {'timeOffset': $('#timeOffset').val(),"
                    + "'dayLightSavingOn': $('#dayLightSavingOn').val() }");
        }

        @Override
        public void renderHead(Component component, IHeaderResponse response) {

            // Date.prototype.getTimezoneOffset() returns negative value if the local time is ahead of UTC,
            // so we invert the result, before sending it to Wicket
            String getTimeOffsetScript = ";var timeOffset = $('#timeOffset');timeOffset.val(new Date().getTimezoneOffset()*60*1000*-1);"
                    + ";var dayLightSavingOn = $('#dayLightSavingOn');dayLightSavingOn.val(isDayLightSavingOn());";
            response.render(OnLoadHeaderItem.forScript(getCallbackScript().toString()));
            response.render(OnLoadHeaderItem.forScript(getTimeOffsetScript));
        }

    });

}

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

License:Apache License

/**
 * /* w w w.  ja va 2 s  .c o m*/
 * @param component
 * @param attributes
 * @return the attributes as string in JSON format
 */
protected final CharSequence renderAjaxAttributes(final Component component,
        final AjaxRequestAttributes attributes) {
    final JSONObject attributesJson = new JSONObject();

    try {
        attributesJson.put("u", getCallbackUrl());

        appendIfNotEmpty(attributesJson, "f", attributes.getFormId());
        appendBooleanIf(attributesJson, "mp", attributes.isMultipart(), true);
        appendIfNotEmpty(attributesJson, "sc", attributes.getSubmittingComponentName());
        appendIfNotEmpty(attributesJson, "i", findIndicatorId());
        appendListenerAtts(attributesJson, attributes.getAjaxCallListeners());
        appendDynamicExtraParameters(attributes.getDynamicExtraParameters(), attributesJson);
        appendBooleanIf(attributesJson, "async", attributes.isAsynchronous(), false);
        appendBooleanIf(attributesJson, "ad", attributes.isAllowDefault(), true);
        appendBooleanIf(attributesJson, "wr", attributes.isWicketAjaxResponse(), false);

        appendSpecial(attributesJson, attributes);

        final ThrottlingSettings throttlingSettings = attributes.getThrottlingSettings();
        if (throttlingSettings != null) {
            final JSONObject throttlingSettingsJson = new JSONObject();
            throttlingSettingsJson.put("id", throttlingSettings.getId());
            throttlingSettingsJson.put("d", throttlingSettings.getDelay().getMilliseconds());
            appendBooleanIf(throttlingSettingsJson, "p", throttlingSettings.getPostponeTimerOnUpdate(), true);
            attributesJson.put("tr", throttlingSettingsJson);
        }

        postprocessConfiguration(attributesJson, component);
    } catch (JSONException e) {
        throw new WicketRuntimeException(e);
    }

    return attributesJson.toString();
}

From source file:com.gmail.volodymyrdotsenko.jqxwicket.core.ajax.JQueryAjaxPostBehavior.java

License:Apache License

@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
    super.updateAjaxAttributes(attributes);

    attributes.setMethod(Method.POST);

    if (this.components.length > 0) {
        StringBuilder serialize = new StringBuilder("var result = [];");

        for (FormComponent<?> component : this.components) {
            serialize.append("result = result.concat(Wicket.Form.serializeElement(Wicket.$('")
                    .append(component.getMarkupId()).append("')));");
        }//  w ww  . j  a  va  2 s .c  o  m

        serialize.append("return result;");

        List<CharSequence> dynamicParameters = attributes.getDynamicExtraParameters();
        dynamicParameters.add(serialize);
    }
}

From source file:net.dontdrinkandroot.wicket.behavior.ajax.KeyEventBehavior.java

License:Apache License

@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {

    super.updateAjaxAttributes(attributes);

    StringBuffer keyEvtBuffer = new StringBuffer();
    keyEvtBuffer.append("return {");
    keyEvtBuffer.append("'keyEvent.altKey': attrs.event.altKey,");
    keyEvtBuffer.append("'keyEvent.charCode': attrs.event.charCode,");
    keyEvtBuffer.append("'keyEvent.ctrlKey': attrs.event.ctrlKey,");
    keyEvtBuffer.append("'keyEvent.keyCode': attrs.event.keyCode,");
    keyEvtBuffer.append("'keyEvent.metaKey': attrs.event.metaKey,");
    keyEvtBuffer.append("'keyEvent.shiftKey': attrs.event.shiftKey,");
    keyEvtBuffer.append("'keyEvent.which': attrs.event.which");
    keyEvtBuffer.append("}");

    attributes.getDynamicExtraParameters().add(keyEvtBuffer.toString());
}

From source file:org.apache.isis.viewer.wicket.ui.components.scalars.XEditableBehavior2.java

License:Apache License

protected AjaxEventBehavior newValidateListener() {
    return new AjaxEventBehavior("validate") {

        /**//from w  w  w  . j av a2 s  . c o m
         * what's bound to "validate" event in Javascript, and sent to the server
         */
        @Override
        protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
            super.updateAjaxAttributes(attributes);
            attributes.getDynamicExtraParameters()
                    .add("return [{'name':'newValue', 'value': attrs.event.extraData.newValue}]");
        }

        /**
         * What's received at the server
         */
        @Override
        protected void onEvent(AjaxRequestTarget target) {
            StringValue newValue = RequestCycle.get().getRequest().getRequestParameters()
                    .getParameterValue("newValue");
            onValidate(target, newValue.toString());
        }

    };
}

From source file:org.cast.cwm.data.behavior.EventLoggingBehavior.java

License:Open Source License

@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
    super.updateAjaxAttributes(attributes);

    if (queryStringExpression != null) {
        // Add detail string dynamically
        attributes.getDynamicExtraParameters()
                .add(String.format("{ %s : %s }", queryVar, queryStringExpression));
    }//from  ww  w . ja  v  a2s  . c  o m
}

From source file:org.cyclop.web.panels.queryeditor.editor.EditorPanel.java

License:Apache License

private void initEditor() {
    editor = new TextArea<>("queryEditor", editorModel);
    editor.setEscapeModelStrings(false);
    add(editor);//from  www.  j  ava 2 s. c  o  m
    editor.add(new OnChangeAjaxBehavior() {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {

            Component cmp = getComponent();
            String editorValue = cmp.getDefaultModelObjectAsString();

            ContextCqlCompletion cqlCompletion;
            if (StringUtils.isEmpty(editorValue)) {
                cqlCompletion = completionService.findInitialCompletion();
            } else {
                RequestCycle requestCycle = RequestCycle.get();
                int index = requestCycle.getRequest().getRequestParameters().getParameterValue("cursorPos")
                        .toInt();
                CqlQuery cqlQuery = new CqlQuery(CqlQueryType.UNKNOWN, editorValue);
                cqlCompletion = completionService.findCompletion(cqlQuery, index);
            }
            if (cqlCompletion.cqlCompletion.isEmpty() || cqlCompletion.equals(currentCompletion)) {
                return;
            }

            fireCompletionChanged(cqlCompletion);
            String suggestsScript = generateReplaceSuggestsJs(editorMarkupIdJq,
                    cqlCompletion.cqlCompletion.fullCompletion);
            target.appendJavaScript(suggestsScript);

            for (CompletionChangeListener list : completionChangeListeners) {
                Component refresh = list.getReferencesForRefresh();
                if (refresh == null) {
                    continue;
                }
                target.add(refresh);
            }
        }

        @Override
        protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
            attributes.getDynamicExtraParameters()
                    .add("return {'cursorPos' : getCaretPosition(" + editorMarkupIdJs + ")}");
            super.updateAjaxAttributes(attributes);
        }
    });
}

From source file:org.hippoecm.frontend.plugins.cms.root.UrlControllerBehavior.java

License:Apache License

@Override
protected void updateAjaxAttributes(final AjaxRequestAttributes attributes) {
    super.updateAjaxAttributes(attributes);
    final List<CharSequence> dep = attributes.getDynamicExtraParameters();
    dep.add("return { " + URL_PARAMETERS + ": params };");
}

From source file:org.hippoecm.frontend.plugins.console.behavior.ParameterHistoryBehavior.java

License:Apache License

@Override
protected void updateAjaxAttributes(final AjaxRequestAttributes attributes) {
    super.updateAjaxAttributes(attributes);
    final List<CharSequence> dep = attributes.getDynamicExtraParameters();
    dep.add("return { " + PATH_PARAMETER + ": path };");
    dep.add("return { " + UUID_PARAMETER + ": uuid };");
}