Example usage for org.apache.wicket.request IRequestParameters getParameterValue

List of usage examples for org.apache.wicket.request IRequestParameters getParameterValue

Introduction

In this page you can find the example usage for org.apache.wicket.request IRequestParameters getParameterValue.

Prototype

StringValue getParameterValue(String name);

Source Link

Document

Returns single value for parameter with specified name.

Usage

From source file:au.com.scds.chats.webapp.SimpleApplication.java

License:Apache License

@Override
public Session newSession(final Request request, final Response response) {
    if (!DEMO_MODE_USING_CREDENTIALS_AS_QUERYARGS) {
        return super.newSession(request, response);
    }/*from w w  w  .  j  a v  a 2  s  . c om*/

    // else demo mode
    final AuthenticatedWebSessionForIsis s = (AuthenticatedWebSessionForIsis) super.newSession(request,
            response);
    IRequestParameters requestParameters = request.getRequestParameters();
    final org.apache.wicket.util.string.StringValue user = requestParameters.getParameterValue("user");
    final org.apache.wicket.util.string.StringValue password = requestParameters.getParameterValue("pass");
    s.signIn(user.toString(), password.toString());
    return s;
}

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  .  j  a  v a  2s.com*/

    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);
    }/* ww w .  ja  va  2  s . c  o 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.cubeia.games.poker.admin.wicket.pages.tournaments.scheduled.EditTournament.java

License:Open Source License

private void addPreviewSchedule(Form<ScheduledTournamentConfiguration> tournamentForm) {
    WebMarkupContainer pc = new WebMarkupContainer("previewContainer");
    pc.setOutputMarkupId(true);// w w  w .  j av  a  2s.  c  om

    final SchedulePreviewPanel previewContent = new SchedulePreviewPanel("previewContent");
    previewContent.setOutputMarkupId(true);

    TournamentSchedule schedule = tournament.getSchedule();

    if (schedule != null) {
        previewContent.setSchedule(schedule);
    }

    pcAjaxBehaviour = new AbstractDefaultAjaxBehavior() {
        @Override
        protected void respond(AjaxRequestTarget target) {

            IRequestParameters params = getRequestCycle().getRequest().getRequestParameters();

            SimpleDateFormat sdf = new SimpleDateFormat(new DateTextField("dummy").getTextFormat());

            String cron = params.getParameterValue("cron").toOptionalString();

            int minInAnnounced = params.getParameterValue("announceMinutes").toInt(0);
            int minInRegistering = params.getParameterValue("registeringMinutes").toInt(0);
            int minAfterClose = params.getParameterValue("visibleMinutes").toInt(0);

            Date start = new Date(0);
            Date end = new Date(0);
            try {
                start = sdf.parse(params.getParameterValue("start").toString());
                end = sdf.parse(params.getParameterValue("end").toString());
            } catch (ParseException e) {
                log.warn("error parsing start/end date");
            }

            updatePreviewValues(previewContent, cron, start, end, minInAnnounced, minInRegistering,
                    minAfterClose);

            target.add(previewContent);
        }

    };
    pc.add(pcAjaxBehaviour);
    pc.add(previewContent);

    tournamentForm.add(pc);
}

From source file:com.evolveum.midpoint.web.page.admin.resources.PageResourceVisualizationCytoscape.java

License:Apache License

private void initLayout(PrismObject<ResourceType> resourceObject) {
    retrievalBehavior = new AbstractAjaxBehavior() {
        @Override//from w  w w.j  av  a2s  .co  m
        public void onRequest() {
            System.out.println("retrieve CS data: starting");
            RequestCycle requestCycle = getRequestCycle();
            requestCycle.scheduleRequestHandlerAfterCurrent(null);

            MidPointApplication app = (MidPointApplication) MidPointApplication.get();
            TaskManager taskManager = app.getTaskManager();
            Task task = taskManager.createTaskInstance(PageResourceVisualizationCytoscape.class + ".onRequest");

            String jsonData;
            try {
                jsonData = app.getModelDiagnosticService().exportDataModel(resourceObject.asObjectable(),
                        DataModelVisualizer.Target.CYTOSCAPE, task, task.getResult());
                System.out.println("JSON Cytoscape Data:\n" + jsonData);
            } catch (CommonException | RuntimeException e) {
                LoggingUtils.logUnexpectedException(LOGGER, "Couldn't visualize resource {}", e,
                        resourceObject);
                jsonData = "{\"nodes\":[], \"edges\":[]}"; // TODO better error handling
            }

            IResource jsonResource = new ByteArrayResource("application/json", jsonData.getBytes());
            IRequestHandler requestHandler = new ResourceRequestHandler(jsonResource, null);
            requestHandler.respond(requestCycle);
            System.out.println("retrieve CS data: response written");
        }
    };
    add(retrievalBehavior);

    deletionBehavior = new AbstractAjaxBehavior() {
        @Override
        public void onRequest() {
            System.out.println("deleteAttribute: starting");
            RequestCycle requestCycle = getRequestCycle();
            requestCycle.scheduleRequestHandlerAfterCurrent(null);

            MidPointApplication app = (MidPointApplication) MidPointApplication.get();
            TaskManager taskManager = app.getTaskManager();
            Task task = taskManager.createTaskInstance(PageResourceVisualizationCytoscape.class + ".onRequest");

            try {
                IRequestParameters parameters = requestCycle.getRequest().getQueryParameters();
                String resourceOid = parameters.getParameterValue("resourceOid").toString();
                String kind = parameters.getParameterValue("kind").toString();
                String intent = parameters.getParameterValue("intent").toString();
                String objectClass = parameters.getParameterValue("objectClass").toString();
                String attributeName = parameters.getParameterValue("attributeName").toString();
                System.out.println("ResourceOid: " + resourceOid + ", kind: " + kind + ", intent: " + intent
                        + ", objectClass: " + objectClass + ", attributeName: " + attributeName);
            } catch (RuntimeException e) {
                LoggingUtils.logUnexpectedException(LOGGER, "Couldn't delete attribute", e);
            }

            IResource resource = new ByteArrayResource("text/plain", "OK".getBytes());
            IRequestHandler requestHandler = new ResourceRequestHandler(resource, null);
            requestHandler.respond(requestCycle);
            System.out.println("deleteAttribute: finished");
        }
    };
    add(deletionBehavior);
}

From source file:com.gitblit.wicket.GitBlitWebSession.java

License:Apache License

/**
 * Cache the requested protected resource pending successful authentication.
 *
 * @param pageClass//  w  w  w  .  ja  va2  s.  com
 */
public void cacheRequest(Class<? extends Page> pageClass) {
    // build absolute url with correctly encoded parameters?!
    Request req = RequestCycle.get().getRequest();
    IRequestParameters params = req.getRequestParameters();
    PageParameters pageParams = new PageParameters();
    params.getParameterNames().forEach(name -> {
        pageParams.add(name, params.getParameterValue(name));
    });
    requestUrl = GitBlitRequestUtils.toAbsoluteUrl(pageClass, pageParams);

    if (isTemporary()) {
        // we must bind the temporary session into the session store
        // so that we can re-use this session for reporting an error message
        // on the redirected page and continuing the request after
        // authentication.
        bind();
    }
}

From source file:com.gmail.volodymyrdotsenko.jqxwicket.core.utils.RequestCycleUtils.java

License:Apache License

/**
 * Gets the value of a query parameter//from w w w.j a  v a 2 s  .  c om
 *
 * @param name the name of the query parameter
 * @return a {@link StringValue}
 */
public static StringValue getQueryParameterValue(String name) {
    final RequestCycle requestCycle = RequestCycle.get();
    final IRequestParameters parameters = requestCycle.getRequest().getQueryParameters();

    return parameters.getParameterValue(name);
}

From source file:com.gmail.volodymyrdotsenko.jqxwicket.core.utils.RequestCycleUtils.java

License:Apache License

/**
 * Gets the value of a post parameter/*from w  w w .j a v a  2s.  co m*/
 *
 * @param name the name of the query parameter
 * @return a {@link StringValue}
 */
public static StringValue getPostParameterValue(String name) {
    final RequestCycle requestCycle = RequestCycle.get();
    final IRequestParameters parameters = requestCycle.getRequest().getPostParameters();

    return parameters.getParameterValue(name);
}

From source file:com.googlecode.wicket.jquery.ui.calendar.CalendarModelBehavior.java

License:Apache License

@Override
public void onRequest() {
    final RequestCycle requestCycle = RequestCycle.get();
    IRequestParameters parameters = requestCycle.getRequest().getQueryParameters();

    final long start = parameters.getParameterValue("start").toLong(0);
    final long end = parameters.getParameterValue("end").toLong(0);

    if (this.model != null) {
        this.model.setStart(new Date(start * 1000));
        this.model.setEnd(new Date(end * 1000));
    }//from   ww  w .ja va2 s  .  c  om

    final IRequestHandler handler = this.newRequestHandler();
    requestCycle.scheduleRequestHandlerAfterCurrent(handler);
}

From source file:com.googlecode.wicket.kendo.ui.datatable.DataProviderBehavior.java

License:Apache License

@Override
public void onRequest() {
    final RequestCycle requestCycle = RequestCycle.get();
    final IRequestParameters parameters = requestCycle.getRequest().getQueryParameters();

    final int first = parameters.getParameterValue("skip").toInt(0);
    final int count = parameters.getParameterValue("take").toInt(0);

    // ISortStateLocator //
    if (this.provider instanceof ISortStateLocator<?>) {
        String property = parameters.getParameterValue("sort[0][field]").toOptionalString();
        String direction = parameters.getParameterValue("sort[0][dir]").toOptionalString();

        if (property != null) {
            this.setSort(PropertyUtils.unescape(property), direction == null ? SortOrder.NONE
                    : direction.equals(ASC) ? SortOrder.ASCENDING : SortOrder.DESCENDING);
        }//from w w w .j  a v  a2 s.  c  om
    }

    // IFilterStateLocator //
    if (this.provider instanceof IFilterStateLocator<?>) {
        @SuppressWarnings("unused")
        String logicPattern = "filter[logic]";
        String fieldPattern = "filter[filters][%d][field]";
        String valuePattern = "filter[filters][%d][value]";

        @SuppressWarnings("unused")
        String operatorPattern = "filter[filters][%d][operator]";
        // TODO: implement logic & operator (new IFilterStateLocator interface?)

        @SuppressWarnings("unchecked")
        T object = ((IFilterStateLocator<T>) this.provider).getFilterState();
        PropertyResolverConverter converter = this.newPropertyResolverConverter();

        for (int i = 0; i < COLS; i++) {
            String field = parameters.getParameterValue(String.format(fieldPattern, i)).toOptionalString();
            String value = parameters.getParameterValue(String.format(valuePattern, i)).toOptionalString();

            if (field != null) {
                PropertyResolver.setValue(PropertyUtils.unescape(field), object, value, converter);
            } else {
                break;
            }
        }
    }

    requestCycle.scheduleRequestHandlerAfterCurrent(this.newRequestHandler(first, count));
}