use of org.apache.tapestry5.runtime.Event 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.runtime.Event in project flowlogix by flowlogix.
the class UpdateEvent method createEvent.
private void createEvent(String event) {
Link link = null;
if (context == null) {
link = cr.createEventLink(event);
} else {
link = cr.createEventLink(event, context);
}
String uri = link.toAbsoluteURI(request.isSecure());
JSONObject spec = new JSONObject();
spec.put("elementId", zone.getClientId());
spec.put("uri", uri);
js.addInitializerCall("updateEvent", spec);
}
use of org.apache.tapestry5.runtime.Event in project tapestry-5 by apache.
the class AjaxComponentEventRequestHandler method handle.
public void handle(ComponentEventRequestParameters parameters) throws IOException {
Page activePage = cache.get(parameters.getActivePageName());
final Holder<Boolean> resultProcessorInvoked = Holder.create();
resultProcessorInvoked.put(false);
ComponentEventResultProcessor interceptor = new ComponentEventResultProcessor() {
public void processResultValue(Object value) throws IOException {
resultProcessorInvoked.put(true);
resultProcessor.processResultValue(value);
}
};
// If we end up doing a partial render, the page render queue service needs to know the
// page that will be rendered (for logging purposes, if nothing else).
queue.setRenderingPage(activePage);
request.setAttribute(InternalConstants.PAGE_NAME_ATTRIBUTE_NAME, parameters.getActivePageName());
if (pageActivator.activatePage(activePage.getRootElement().getComponentResources(), parameters.getPageActivationContext(), interceptor))
return;
Page containerPage = cache.get(parameters.getContainingPageName());
ComponentPageElement element = containerPage.getComponentElementByNestedId(parameters.getNestedComponentId());
// In many cases, the triggered element is a Form that needs to be able to
// pass its event handler return values to the correct result processor.
// This is certainly the case for forms.
TrackableComponentEventCallback callback = new ComponentResultProcessorWrapper(interceptor);
environment.push(ComponentEventResultProcessor.class, interceptor);
environment.push(TrackableComponentEventCallback.class, callback);
boolean handled = element.triggerContextEvent(parameters.getEventType(), parameters.getEventContext(), callback);
if (!handled)
throw new TapestryException(String.format("Request event '%s' (on component %s) was not handled; you must provide a matching event handler method in the component or in one of its containers.", parameters.getEventType(), element.getCompleteId()), element, null);
environment.pop(TrackableComponentEventCallback.class);
environment.pop(ComponentEventResultProcessor.class);
// If the result processor was passed a value, then it will already have rendered. Otherwise it was not passed a value,
// but it's still possible that we still want to do a partial page render ... if filters were added to the render queue.
// In that event, run the partial page render now and return.
boolean wasInvoked = resultProcessorInvoked.get();
if ((!wasInvoked) && queue.isPartialRenderInitialized()) {
partialRenderer.renderPartialPageMarkup();
return;
}
if (wasInvoked) {
return;
}
// Send an empty JSON reply if no value was returned from the component event handler method.
// This is the typical behavior when an Ajax component event handler returns null. It still
// will go through a pipeline that will add information related to partial page rendering.
resultProcessor.processResultValue(new JSONObject());
}
use of org.apache.tapestry5.runtime.Event in project tapestry-5 by apache.
the class ComponentInstanceResultProcessor method processResultValue.
public void processResultValue(Component value) throws IOException {
ComponentResources resources = value.getComponentResources();
if (resources.getContainer() != null) {
logger.warn("Component {} was returned from an event handler method, but is not a page component. The page containing the component will render the client response.", value.getComponentResources().getCompleteId());
}
resultProcessor.processResultValue(resources.getPageName());
}
use of org.apache.tapestry5.runtime.Event in project tapestry-5 by apache.
the class ObjectComponentEventResultProcessor method processResultValue.
public void processResultValue(Object value) throws IOException {
List<String> names = F.flow(configuredClasses).map(new Mapper<Class, String>() {
public String map(Class input) {
return PlasticUtils.toTypeName(input);
}
}).toList();
String message = String.format("A component event handler method returned the value %s. Return type %s can not be handled.", value, PlasticUtils.toTypeName(value.getClass()));
throw new UnknownValueException(message, new AvailableValues("Configured return types", names));
}
Aggregations