Search in sources :

Example 1 with IRequestParameters

use of org.apache.wicket.request.IRequestParameters in project wicket by apache.

the class ServletWebRequest method generatePostParameters.

protected Map<String, List<StringValue>> generatePostParameters() {
    Map<String, List<StringValue>> postParameters = new HashMap<>();
    IRequestParameters queryParams = getQueryParameters();
    @SuppressWarnings("unchecked") Map<String, String[]> params = getContainerRequest().getParameterMap();
    for (Map.Entry<String, String[]> param : params.entrySet()) {
        final String name = param.getKey();
        final String[] values = param.getValue();
        if (name != null && values != null) {
            // build a mutable list of query params that have the same name as the post param
            List<StringValue> queryValues = queryParams.getParameterValues(name);
            if (queryValues == null) {
                queryValues = Collections.emptyList();
            } else {
                queryValues = new ArrayList<>(queryValues);
            }
            // the list that will contain accepted post param values
            List<StringValue> postValues = new ArrayList<>();
            for (String value : values) {
                StringValue val = StringValue.valueOf(value);
                if (queryValues.contains(val)) {
                    // if a query param with this value exists remove it and continue
                    queryValues.remove(val);
                } else {
                    // there is no query param with this value, assume post
                    postValues.add(val);
                }
            }
            if (!postValues.isEmpty()) {
                postParameters.put(name, postValues);
            }
        }
    }
    return postParameters;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) StringValue(org.apache.wicket.util.string.StringValue) HashMap(java.util.HashMap) Map(java.util.Map) IRequestParameters(org.apache.wicket.request.IRequestParameters)

Example 2 with IRequestParameters

use of org.apache.wicket.request.IRequestParameters in project wicket by apache.

the class BehaviorUrlTest method testBehaviorUrlNotDoubleEscaped.

@Test
public void testBehaviorUrlNotDoubleEscaped() {
    tester.startPage(EscapeTestPage.class);
    String response = tester.getLastResponseAsString();
    // System.err.println(response);
    assertTrue(response.contains(EscapeTestPage.TEST_QUERY_STRING));
    tester.executeAjaxEvent("form:textfield", "change");
    EscapeTestPage testPage = (EscapeTestPage) tester.getLastRenderedPage();
    IRequestParameters lastParameters = testPage.getLastQueryParameters();
    assertEquals(StringValue.valueOf("value_1"), lastParameters.getParameterValue("query_p_1"));
}
Also used : IRequestParameters(org.apache.wicket.request.IRequestParameters) Test(org.junit.Test)

Example 3 with IRequestParameters

use of org.apache.wicket.request.IRequestParameters in project wiquery by WiQuery.

the class WiQueryAbstractAjaxBehavior method respond.

@Override
protected void respond(AjaxRequestTarget target) {
    IRequestParameters req = RequestCycle.get().getRequest().getRequestParameters();
    String eventName = req.getParameterValue("eventName").toString();
    IComplexOption callback = options.getComplexOption(eventName);
    if (callback instanceof AbstractAjaxEventCallback) {
        ((AbstractAjaxEventCallback) callback).call(target, getComponent());
    }
}
Also used : IComplexOption(org.odlabs.wiquery.core.options.IComplexOption) IRequestParameters(org.apache.wicket.request.IRequestParameters)

Example 4 with IRequestParameters

use of org.apache.wicket.request.IRequestParameters in project java-design-patterns by iluwatar.

the class SimpleApplication method newSession.

@Override
public Session newSession(final Request request, final Response response) {
    if (!DEMO_MODE_USING_CREDENTIALS_AS_QUERYARGS) {
        return super.newSession(request, response);
    }
    // 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;
}
Also used : AuthenticatedWebSessionForIsis(org.apache.isis.viewer.wicket.viewer.integration.wicket.AuthenticatedWebSessionForIsis) IRequestParameters(org.apache.wicket.request.IRequestParameters)

Example 5 with IRequestParameters

use of org.apache.wicket.request.IRequestParameters in project webanno by webanno.

the class AnnotationPage method createUrlFragmentBehavior.

private UrlParametersReceivingBehavior createUrlFragmentBehavior() {
    return new UrlParametersReceivingBehavior() {

        private static final long serialVersionUID = -3860933016636718816L;

        @Override
        protected void onParameterArrival(IRequestParameters aRequestParameters, AjaxRequestTarget aTarget) {
            aTarget.addChildren(getPage(), IFeedback.class);
            StringValue project = aRequestParameters.getParameterValue(PAGE_PARAM_PROJECT_ID);
            StringValue document = aRequestParameters.getParameterValue(PAGE_PARAM_DOCUMENT_ID);
            StringValue focus = aRequestParameters.getParameterValue(PAGE_PARAM_FOCUS);
            handleParameters(aTarget, project, document, focus, false);
        }
    };
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) UrlParametersReceivingBehavior(de.tudarmstadt.ukp.clarin.webanno.support.wicketstuff.UrlParametersReceivingBehavior) StringValue(org.apache.wicket.util.string.StringValue) IRequestParameters(org.apache.wicket.request.IRequestParameters)

Aggregations

IRequestParameters (org.apache.wicket.request.IRequestParameters)7 StringValue (org.apache.wicket.util.string.StringValue)3 Test (org.junit.Test)2 UrlParametersReceivingBehavior (de.tudarmstadt.ukp.clarin.webanno.support.wicketstuff.UrlParametersReceivingBehavior)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 AuthenticatedWebSessionForIsis (org.apache.isis.viewer.wicket.viewer.integration.wicket.AuthenticatedWebSessionForIsis)1 MockPageParametersAware (org.apache.wicket.MockPageParametersAware)1 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)1 BookmarkablePageRequestHandler (org.apache.wicket.core.request.handler.BookmarkablePageRequestHandler)1 IPageProvider (org.apache.wicket.core.request.handler.IPageProvider)1 PageProvider (org.apache.wicket.core.request.handler.PageProvider)1 WebClientInfo (org.apache.wicket.protocol.http.request.WebClientInfo)1 IRequestHandler (org.apache.wicket.request.IRequestHandler)1 Url (org.apache.wicket.request.Url)1 RequestCycle (org.apache.wicket.request.cycle.RequestCycle)1 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)1 IComplexOption (org.odlabs.wiquery.core.options.IComplexOption)1