Search in sources :

Example 11 with EventContext

use of org.apache.tapestry5.EventContext in project tapestry-5 by apache.

the class Select method onChange.

Object onChange(final EventContext context, @RequestParameter(value = "t:selectvalue", allowBlank = true) final String selectValue) throws ValidationException {
    final Object newValue = toValue(selectValue);
    CaptureResultCallback<Object> callback = new CaptureResultCallback<Object>();
    EventContext newContext = new AbstractEventContext() {

        @Override
        public int getCount() {
            return context.getCount() + 1;
        }

        @Override
        public <T> T get(Class<T> desiredType, int index) {
            if (index == 0) {
                return typeCoercer.coerce(newValue, desiredType);
            }
            return context.get(desiredType, index - 1);
        }
    };
    this.resources.triggerContextEvent(EventConstants.VALUE_CHANGED, newContext, callback);
    this.value = newValue;
    return callback.getResult();
}
Also used : AbstractEventContext(org.apache.tapestry5.internal.AbstractEventContext) CaptureResultCallback(org.apache.tapestry5.internal.util.CaptureResultCallback) AbstractEventContext(org.apache.tapestry5.internal.AbstractEventContext)

Example 12 with EventContext

use of org.apache.tapestry5.EventContext in project tapestry-5 by apache.

the class ComponentEventImplTest method no_match_one_event_is_aborted.

/**
 * @since 5.2.0
 */
@Test
public void no_match_one_event_is_aborted() {
    ComponentEventCallback handler = mockComponentEventHandler();
    EventContext context = mockEventContext();
    Logger logger = mockLogger();
    Object result = new Object();
    ComponentPageElementResources resources = mockResources();
    ComponentModel model = mockComponentModel();
    train_isDebugEnabled(logger, false);
    train_handleResult(handler, result, true);
    replay();
    ComponentEvent event = new ComponentEventImpl("eventType", "someId", context, handler, resources, false, model, logger);
    event.storeResult(result);
    assertFalse(event.matches("eventType", "someId", 0));
    verify();
}
Also used : EventContext(org.apache.tapestry5.EventContext) ComponentModel(org.apache.tapestry5.model.ComponentModel) ComponentPageElementResources(org.apache.tapestry5.internal.structure.ComponentPageElementResources) ComponentEvent(org.apache.tapestry5.runtime.ComponentEvent) Logger(org.slf4j.Logger) ComponentEventCallback(org.apache.tapestry5.ComponentEventCallback) Test(org.testng.annotations.Test)

Example 13 with EventContext

use of org.apache.tapestry5.EventContext in project tapestry-5 by apache.

the class EventContextTests method array_event_context_to_strings.

@Test
public void array_event_context_to_strings() {
    EventContext ec = new ArrayEventContext(typeCoercer, 1, 2.3);
    assertEquals(ec.toStrings(), new String[] { "1", "2.3" });
}
Also used : EmptyEventContext(org.apache.tapestry5.internal.EmptyEventContext) EventContext(org.apache.tapestry5.EventContext) Test(org.testng.annotations.Test)

Example 14 with EventContext

use of org.apache.tapestry5.EventContext in project tapestry-5 by apache.

the class EventContextTests method to_string_of_event_context.

@Test
public void to_string_of_event_context() {
    EventContext ec = new ArrayEventContext(typeCoercer, 1, 2.3);
    assertEquals(ec.toString(), "<EventContext: 1, 2.3>");
}
Also used : EmptyEventContext(org.apache.tapestry5.internal.EmptyEventContext) EventContext(org.apache.tapestry5.EventContext) Test(org.testng.annotations.Test)

Example 15 with EventContext

use of org.apache.tapestry5.EventContext in project tapestry-5 by apache.

the class LinkSourceImplTest method testEventLinkCreation2.

private void testEventLinkCreation2(String pageName, String nestedId, String eventType, boolean forForm, Object... context) {
    Page primaryPage = mockPage();
    PageRenderQueue queue = mockPageRenderQueue();
    PageActivationContextCollector collector = mockPageActivationContextCollector();
    LinkCreationListener2 listener = mockLinkCreationListener2();
    ComponentEventLinkEncoder linkEncoder = mockComponentEventLinkEncoder();
    Link link = mockLink();
    ArrayEventContext eventContext = new ArrayEventContext(typeCoercer, context);
    ArrayEventContext pageEventContext = new ArrayEventContext(typeCoercer, "a", "b");
    train_getRenderingPage(queue, null);
    train_getName(primaryPage, pageName);
    train_collectPageActivationContext(collector, pageName, "a", "b");
    ComponentEventRequestParameters parameters = new ComponentEventRequestParameters(pageName, pageName, nestedId, eventType, pageEventContext, eventContext);
    expect(linkEncoder.createComponentEventLink(parameters, forForm)).andReturn(link);
    listener.createdComponentEventLink(link, parameters);
    List<LinkCreationListener2> configuration = CollectionFactory.newList(listener);
    replay();
    LinkSource source = new LinkSourceImpl(queue, collector, typeCoercer, null, linkEncoder, null, null, configuration);
    Link returnedLink = source.createComponentEventLink(primaryPage, nestedId, eventType, forForm, context);
    // Make sure the same link is returned.
    assertSame(returnedLink, link);
    verify();
}
Also used : ComponentEventLinkEncoder(org.apache.tapestry5.services.ComponentEventLinkEncoder) ComponentEventRequestParameters(org.apache.tapestry5.services.ComponentEventRequestParameters) Page(org.apache.tapestry5.internal.structure.Page) LinkCreationListener2(org.apache.tapestry5.services.LinkCreationListener2) Link(org.apache.tapestry5.http.Link)

Aggregations

EventContext (org.apache.tapestry5.EventContext)16 Test (org.testng.annotations.Test)15 Logger (org.slf4j.Logger)9 ComponentEventCallback (org.apache.tapestry5.ComponentEventCallback)8 Link (org.apache.tapestry5.http.Link)8 ComponentModel (org.apache.tapestry5.model.ComponentModel)8 ComponentEvent (org.apache.tapestry5.runtime.ComponentEvent)8 Page (org.apache.tapestry5.internal.structure.Page)5 ComponentEventRequestParameters (org.apache.tapestry5.services.ComponentEventRequestParameters)5 EmptyEventContext (org.apache.tapestry5.internal.EmptyEventContext)4 ComponentEventLinkEncoder (org.apache.tapestry5.services.ComponentEventLinkEncoder)4 AbstractEventContext (org.apache.tapestry5.internal.AbstractEventContext)3 ComponentPageElementResources (org.apache.tapestry5.internal.structure.ComponentPageElementResources)3 JSONObject (org.apache.tapestry5.json.JSONObject)3 ComponentClassResolver (org.apache.tapestry5.services.ComponentClassResolver)3 LinkCreationListener2 (org.apache.tapestry5.services.LinkCreationListener2)3 PageRenderRequestParameters (org.apache.tapestry5.services.PageRenderRequestParameters)3 Request (org.apache.tapestry5.http.services.Request)2 PageRenderLinkSource (org.apache.tapestry5.services.PageRenderLinkSource)2 IOException (java.io.IOException)1