use of org.apache.tapestry5.EventContext in project tapestry-5 by apache.
the class AjaxFormLoop method onInjectRow.
Object onInjectRow(EventContext context) {
ComponentEventCallback callback = new ComponentEventCallback() {
public boolean handleResult(Object result) {
value = result;
return true;
}
};
resources.triggerContextEvent(EventConstants.ADD_ROW, context, callback);
if (value == null)
throw new IllegalArgumentException(String.format("Event handler for event 'addRow' from %s should have returned a non-null value.", resources.getCompleteId()));
ajaxResponseRenderer.addFilter(new PartialMarkupRendererFilter() {
public void renderMarkup(MarkupWriter writer, JSONObject reply, PartialMarkupRenderer renderer) {
pushContext();
renderer.renderMarkup(writer, reply);
popContext();
}
});
return ajaxResponse;
}
use of org.apache.tapestry5.EventContext in project tapestry-5 by apache.
the class TapestryModule method contributeObjectRenderer.
/**
* Contributes a default object renderer for type Object, plus specialized
* renderers for {@link org.apache.tapestry5.http.services.Request}, {@link org.apache.tapestry5.commons.Location},
* {@link org.apache.tapestry5.ComponentResources}, {@link org.apache.tapestry5.EventContext},
* {@link AvailableValues},
* List, and Object[].
*/
@SuppressWarnings("unchecked")
public void contributeObjectRenderer(MappedConfiguration<Class, ObjectRenderer> configuration, @InjectService("LocationRenderer") ObjectRenderer locationRenderer, final TypeCoercer typeCoercer) {
configuration.add(Object.class, new DefaultObjectRenderer());
configuration.addInstance(Request.class, RequestRenderer.class);
configuration.add(Location.class, locationRenderer);
ObjectRenderer preformatted = new ObjectRenderer<Object>() {
public void render(Object object, MarkupWriter writer) {
writer.element("pre");
writer.write(typeCoercer.coerce(object, String.class));
writer.end();
}
};
configuration.addInstance(List.class, ListRenderer.class);
configuration.addInstance(Object[].class, ObjectArrayRenderer.class);
configuration.addInstance(ComponentResources.class, ComponentResourcesRenderer.class);
configuration.addInstance(EventContext.class, EventContextRenderer.class);
configuration.add(AvailableValues.class, new AvailableValuesRenderer());
}
use of org.apache.tapestry5.EventContext in project tapestry-5 by apache.
the class PageActivatorImpl method activatePage.
@SuppressWarnings("rawtypes")
public boolean activatePage(ComponentResources pageResources, EventContext activationContext, ComponentEventResultProcessor resultProcessor) throws IOException {
TrackableComponentEventCallback callback = new ComponentResultProcessorWrapper(resultProcessor);
boolean handled = pageResources.triggerContextEvent(EventConstants.ACTIVATE, activationContext, callback);
boolean acceptEmpty = !pageResources.getComponentModel().handlesEvent(EventConstants.ACTIVATE) && activationContext.getCount() == 0;
boolean checkUnknown = metaDataLocator.findMeta(MetaDataConstants.UNKNOWN_ACTIVATION_CONTEXT_CHECK, pageResources, Boolean.class);
if (!handled && !acceptEmpty && checkUnknown && !pageResources.getComponentModel().handleActivationEventContext()) {
logger.info("Page {} required an exact activation context, let's handle this", pageResources.getPageName());
unknownActivationContextHandler.handleUnknownContext(pageResources, activationContext);
return true;
}
if (callback.isAborted()) {
callback.rethrow();
return true;
} else {
if (InternalConstants.TRUE.equals(pageResources.getComponentModel().getMeta(InternalConstants.REST_ENDPOINT_EVENT_HANDLER_METHOD_PRESENT))) {
callback = new ComponentResultProcessorWrapper(resultProcessor);
handled = pageResources.triggerContextEvent(InternalConstants.HTTP_METHOD_EVENT_PREFIX + request.getMethod(), activationContext, callback);
if (callback.isAborted()) {
callback.rethrow();
return true;
} else {
throw new RestEndpointNotFoundException(String.format("Page %s (%s) has at least one REST endpoint event handler method " + "but none handled %s for this request", pageResources.getPageName(), pageResources.getPage().getClass().getName(), request.getMethod()));
}
}
}
return false;
}
use of org.apache.tapestry5.EventContext in project tapestry-5 by apache.
the class ComponentEventImplTest method unable_to_coerce.
@Test
public void unable_to_coerce() {
ComponentEventCallback handler = mockComponentEventHandler();
EventContext context = mockEventContext();
ComponentPageElementResources resources = mockComponentPageElementResources();
Logger logger = mockLogger();
ComponentModel model = mockComponentModel();
train_isDebugEnabled(logger, true);
logger.debug(eq(TapestryMarkers.EVENT_HANDLER_METHOD), isA(String.class));
train_toClass(resources, Integer.class.getName(), Integer.class);
train_getCount(context, 1);
expect(context.get(Integer.class, 0)).andThrow(new NumberFormatException("Not so easy, is it?"));
replay();
ComponentEvent event = new ComponentEventImpl("eventType", "someId", context, handler, resources, false, model, logger);
event.setMethodDescription("foo.Bar.baz()");
try {
event.coerceContext(0, "java.lang.Integer");
unreachable();
} catch (IllegalArgumentException ex) {
// Different JVMs will report the conversion error slightly differently,
// so we don't try to check that part of the error message.
assertTrue(ex.getMessage().startsWith("Exception in method foo.Bar.baz(), parameter #1:"));
}
verify();
}
use of org.apache.tapestry5.EventContext in project tapestry-5 by apache.
the class ComponentEventImplTest method event_type_match_is_case_insensitive.
@Test
public void event_type_match_is_case_insensitive() {
ComponentEventCallback handler = mockComponentEventHandler();
EventContext context = mockEventContext();
Logger logger = mockLogger();
ComponentModel model = mockComponentModel();
train_isDebugEnabled(logger, false);
train_getCount(context, 0);
replay();
ComponentEvent event = new ComponentEventImpl("eventType", "someId", context, handler, null, false, model, logger);
assertTrue(event.matches("EVENTTYPE", "someid", 0));
verify();
}
Aggregations