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();
}
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();
}
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" });
}
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>");
}
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();
}
Aggregations