Search in sources :

Example 81 with Page

use of org.apache.wicket.Page in project wicket by apache.

the class AnnotatedFieldInBehaviorPage method beanInjectedInBehavior.

/**
 * https://issues.apache.org/jira/browse/WICKET-4149
 */
@Test
public void beanInjectedInBehavior() {
    ctx.putBean("mrBean", new Bean());
    // with no name specified we get IllegalStateException
    Page page = tester.startPage(new AnnotatedFieldInBehaviorPage());
    TestBehavior behavior = page.getBehaviors(TestBehavior.class).get(0);
    assertNotNull(behavior.getBean());
}
Also used : DummyHomePage(org.apache.wicket.util.tester.DummyHomePage) Page(org.apache.wicket.Page) Bean(org.apache.wicket.spring.Bean) Test(org.junit.Test)

Example 82 with Page

use of org.apache.wicket.Page in project wicket by apache.

the class AutoConversationManager method onBeforeRender.

@Override
public void onBeforeRender(Component component) {
    if (component instanceof Page) {
        Page page = (Page) component;
        IRequestHandler activeRequestHandler = page.getRequestCycle().getActiveRequestHandler();
        autoEndIfNecessary(page, activeRequestHandler);
        autoBeginIfNecessary(page, activeRequestHandler);
    }
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) Page(org.apache.wicket.Page)

Example 83 with Page

use of org.apache.wicket.Page in project wicket by apache.

the class AbstractDefaultAjaxBehavior method renderAjaxAttributes.

/**
 * @param component
 * @param attributes
 * @return the attributes as string in JSON format
 */
protected final CharSequence renderAjaxAttributes(final Component component, AjaxRequestAttributes attributes) {
    JSONObject attributesJson = new JSONObject();
    try {
        attributesJson.put(AjaxAttributeName.URL.jsonName(), getCallbackUrl());
        Method method = attributes.getMethod();
        if (Method.POST == method) {
            attributesJson.put(AjaxAttributeName.METHOD.jsonName(), method);
        }
        if (component instanceof Page == false) {
            String componentId = component.getMarkupId();
            attributesJson.put(AjaxAttributeName.MARKUP_ID.jsonName(), componentId);
        }
        String formId = attributes.getFormId();
        if (Strings.isEmpty(formId) == false) {
            attributesJson.put(AjaxAttributeName.FORM_ID.jsonName(), formId);
        }
        if (attributes.isMultipart()) {
            attributesJson.put(AjaxAttributeName.IS_MULTIPART.jsonName(), true);
        }
        String submittingComponentId = attributes.getSubmittingComponentName();
        if (Strings.isEmpty(submittingComponentId) == false) {
            attributesJson.put(AjaxAttributeName.SUBMITTING_COMPONENT_NAME.jsonName(), submittingComponentId);
        }
        CharSequence childSelector = attributes.getChildSelector();
        if (Strings.isEmpty(childSelector) == false) {
            attributesJson.put(AjaxAttributeName.CHILD_SELECTOR.jsonName(), childSelector);
        }
        if (attributes.isSerializeRecursively()) {
            attributesJson.put(AjaxAttributeName.SERIALIZE_RECURSIVELY.jsonName(), true);
        }
        String indicatorId = findIndicatorId();
        if (Strings.isEmpty(indicatorId) == false) {
            attributesJson.put(AjaxAttributeName.INDICATOR_ID.jsonName(), indicatorId);
        }
        for (IAjaxCallListener ajaxCallListener : attributes.getAjaxCallListeners()) {
            if (ajaxCallListener != null) {
                CharSequence initHandler = ajaxCallListener.getInitHandler(component);
                appendListenerHandler(initHandler, attributesJson, AjaxAttributeName.INIT_HANDLER.jsonName(), INIT_HANDLER_FUNCTION_TEMPLATE);
                CharSequence beforeHandler = ajaxCallListener.getBeforeHandler(component);
                appendListenerHandler(beforeHandler, attributesJson, AjaxAttributeName.BEFORE_HANDLER.jsonName(), BEFORE_HANDLER_FUNCTION_TEMPLATE);
                CharSequence beforeSendHandler = ajaxCallListener.getBeforeSendHandler(component);
                appendListenerHandler(beforeSendHandler, attributesJson, AjaxAttributeName.BEFORE_SEND_HANDLER.jsonName(), BEFORE_SEND_HANDLER_FUNCTION_TEMPLATE);
                CharSequence afterHandler = ajaxCallListener.getAfterHandler(component);
                appendListenerHandler(afterHandler, attributesJson, AjaxAttributeName.AFTER_HANDLER.jsonName(), AFTER_HANDLER_FUNCTION_TEMPLATE);
                CharSequence successHandler = ajaxCallListener.getSuccessHandler(component);
                appendListenerHandler(successHandler, attributesJson, AjaxAttributeName.SUCCESS_HANDLER.jsonName(), SUCCESS_HANDLER_FUNCTION_TEMPLATE);
                CharSequence failureHandler = ajaxCallListener.getFailureHandler(component);
                appendListenerHandler(failureHandler, attributesJson, AjaxAttributeName.FAILURE_HANDLER.jsonName(), FAILURE_HANDLER_FUNCTION_TEMPLATE);
                CharSequence completeHandler = ajaxCallListener.getCompleteHandler(component);
                appendListenerHandler(completeHandler, attributesJson, AjaxAttributeName.COMPLETE_HANDLER.jsonName(), COMPLETE_HANDLER_FUNCTION_TEMPLATE);
                CharSequence precondition = ajaxCallListener.getPrecondition(component);
                appendListenerHandler(precondition, attributesJson, AjaxAttributeName.PRECONDITION.jsonName(), PRECONDITION_FUNCTION_TEMPLATE);
                CharSequence doneHandler = ajaxCallListener.getDoneHandler(component);
                appendListenerHandler(doneHandler, attributesJson, AjaxAttributeName.DONE_HANDLER.jsonName(), DONE_HANDLER_FUNCTION_TEMPLATE);
            }
        }
        JSONArray extraParameters = JsonUtils.asArray(attributes.getExtraParameters());
        if (extraParameters.length() > 0) {
            attributesJson.put(AjaxAttributeName.EXTRA_PARAMETERS.jsonName(), extraParameters);
        }
        List<CharSequence> dynamicExtraParameters = attributes.getDynamicExtraParameters();
        if (dynamicExtraParameters != null) {
            for (CharSequence dynamicExtraParameter : dynamicExtraParameters) {
                String func = String.format(DYNAMIC_PARAMETER_FUNCTION_TEMPLATE, dynamicExtraParameter);
                JSONFunction function = new JSONFunction(func);
                attributesJson.append(AjaxAttributeName.DYNAMIC_PARAMETER_FUNCTION.jsonName(), function);
            }
        }
        if (attributes.isAsynchronous() == false) {
            attributesJson.put(AjaxAttributeName.IS_ASYNC.jsonName(), false);
        }
        String[] eventNames = attributes.getEventNames();
        if (eventNames.length == 1) {
            attributesJson.put(AjaxAttributeName.EVENT_NAME.jsonName(), eventNames[0]);
        } else {
            for (String eventName : eventNames) {
                attributesJson.append(AjaxAttributeName.EVENT_NAME.jsonName(), eventName);
            }
        }
        AjaxChannel channel = attributes.getChannel();
        if (channel != null && channel.equals(AjaxChannel.DEFAULT) == false) {
            attributesJson.put(AjaxAttributeName.CHANNEL.jsonName(), channel);
        }
        if (attributes.isPreventDefault()) {
            attributesJson.put(AjaxAttributeName.IS_PREVENT_DEFAULT.jsonName(), true);
        }
        if (AjaxRequestAttributes.EventPropagation.STOP.equals(attributes.getEventPropagation())) {
            attributesJson.put(AjaxAttributeName.EVENT_PROPAGATION.jsonName(), "stop");
        } else if (AjaxRequestAttributes.EventPropagation.STOP_IMMEDIATE.equals(attributes.getEventPropagation())) {
            attributesJson.put(AjaxAttributeName.EVENT_PROPAGATION.jsonName(), "stopImmediate");
        }
        Duration requestTimeout = attributes.getRequestTimeout();
        if (requestTimeout != null) {
            attributesJson.put(AjaxAttributeName.REQUEST_TIMEOUT.jsonName(), requestTimeout.getMilliseconds());
        }
        boolean wicketAjaxResponse = attributes.isWicketAjaxResponse();
        if (wicketAjaxResponse == false) {
            attributesJson.put(AjaxAttributeName.IS_WICKET_AJAX_RESPONSE.jsonName(), false);
        }
        String dataType = attributes.getDataType();
        if (AjaxRequestAttributes.XML_DATA_TYPE.equals(dataType) == false) {
            attributesJson.put(AjaxAttributeName.DATATYPE.jsonName(), dataType);
        }
        ThrottlingSettings throttlingSettings = attributes.getThrottlingSettings();
        if (throttlingSettings != null) {
            JSONObject throttlingSettingsJson = new JSONObject();
            String throttleId = throttlingSettings.getId();
            if (throttleId == null) {
                throttleId = component.getMarkupId();
            }
            throttlingSettingsJson.put(AjaxAttributeName.THROTTLING_ID.jsonName(), throttleId);
            throttlingSettingsJson.put(AjaxAttributeName.THROTTLING_DELAY.jsonName(), throttlingSettings.getDelay().getMilliseconds());
            if (throttlingSettings.getPostponeTimerOnUpdate()) {
                throttlingSettingsJson.put(AjaxAttributeName.THROTTLING_POSTPONE_ON_UPDATE.jsonName(), true);
            }
            attributesJson.put(AjaxAttributeName.THROTTLING.jsonName(), throttlingSettingsJson);
        }
        postprocessConfiguration(attributesJson, component);
    } catch (JSONException e) {
        throw new WicketRuntimeException(e);
    }
    String attributesAsJson = attributesJson.toString();
    return attributesAsJson;
}
Also used : ThrottlingSettings(org.apache.wicket.ajax.attributes.ThrottlingSettings) IAjaxCallListener(org.apache.wicket.ajax.attributes.IAjaxCallListener) WicketRuntimeException(org.apache.wicket.WicketRuntimeException) JSONArray(com.github.openjson.JSONArray) JSONException(com.github.openjson.JSONException) Page(org.apache.wicket.Page) Duration(org.apache.wicket.util.time.Duration) Method(org.apache.wicket.ajax.attributes.AjaxRequestAttributes.Method) JSONFunction(org.apache.wicket.ajax.json.JSONFunction) JSONObject(com.github.openjson.JSONObject)

Example 84 with Page

use of org.apache.wicket.Page in project wicket by apache.

the class AjaxNewWindowNotifyingBehavior method onNewWindow.

/**
 * A callback method when a new window/tab is opened for a page instance which is already opened
 * in another window/tab.
 * <p>
 * Default implementation redirects to a new page instance with identical page parameters.
 *
 * @param target
 *            the current request handler
 */
protected void onNewWindow(AjaxRequestTarget target) {
    Page page = getComponent().getPage();
    getComponent().setResponsePage(page.getClass(), page.getPageParameters());
}
Also used : Page(org.apache.wicket.Page)

Example 85 with Page

use of org.apache.wicket.Page in project wicket by apache.

the class CdiWicketTester method urlFor.

@Override
public Url urlFor(IRequestHandler handler) {
    Url ret = super.urlFor(handler);
    final CdiConfiguration configuration = CdiConfiguration.get(getApplication());
    Page page = ConversationPropagator.getPage(handler);
    if (configuration.getPropagation().propagatesVia(handler, page)) {
        if (page != null) {
            String cid = ConversationPropagator.getConversationIdFromPage(page);
            ret.addQueryParameter(ConversationPropagator.CID, cid);
        }
    }
    return ret;
}
Also used : Page(org.apache.wicket.Page) Url(org.apache.wicket.request.Url)

Aggregations

Page (org.apache.wicket.Page)94 Test (org.junit.Test)50 WebPage (org.apache.wicket.markup.html.WebPage)22 Component (org.apache.wicket.Component)11 AjaxLink (org.apache.wicket.ajax.markup.html.AjaxLink)7 IRequestablePage (org.apache.wicket.request.component.IRequestablePage)7 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)6 IRequestHandler (org.apache.wicket.request.IRequestHandler)6 RequestCycle (org.apache.wicket.request.cycle.RequestCycle)6 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)6 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)5 PageProvider (org.apache.wicket.core.request.handler.PageProvider)5 IMarkupFragment (org.apache.wicket.markup.IMarkupFragment)5 DummyPage (org.apache.wicket.resource.DummyPage)5 ArrayList (java.util.ArrayList)4 AbstractAjaxBehavior (org.apache.wicket.behavior.AbstractAjaxBehavior)4 AccessDeniedPage (org.apache.wicket.markup.html.pages.AccessDeniedPage)4 Url (org.apache.wicket.request.Url)4 MockInnerClassPage (org.apache.wicket.util.tester.MockPageParameterPage.MockInnerClassPage)4 SuccessPage (org.apache.wicket.util.tester.apps_1.SuccessPage)4