use of org.apache.tapestry5.internal.structure.ComponentPageElement in project tapestry-5 by apache.
the class InternalComponentResourcesImplTest method render_informal_parameters_skips_formal_parameters.
@Test
public void render_informal_parameters_skips_formal_parameters() {
ComponentPageElement element = mockComponentPageElement();
Component component = mockComponent();
Instantiator ins = mockInstantiator(component);
MarkupWriter writer = mockMarkupWriter();
ComponentModel model = mockComponentModel();
ParameterModel pmodel = mockParameterModel();
Binding binding = mockBinding();
train_getModel(ins, model);
train_getParameterModel(model, "fred", pmodel);
replay();
InternalComponentResources resources = new InternalComponentResourcesImpl(null, element, null, elementResources, null, null, ins, false);
resources.bindParameter("fred", binding);
resources.renderInformalParameters(writer);
verify();
}
use of org.apache.tapestry5.internal.structure.ComponentPageElement in project tapestry-5 by apache.
the class PageImplTest method detach_dirty_if_listener_throws_exception.
/**
* Also checks that all listeners are invoked, even if one of them throws an exception.
*/
@Test
public void detach_dirty_if_listener_throws_exception() {
ComponentPageElement element = mockComponentPageElement();
Logger logger = mockLogger();
PageLifecycleListener listener1 = newPageLifecycle();
PageLifecycleListener listener2 = newPageLifecycle();
RuntimeException t = new RuntimeException("Listener detach exception.");
MetaDataLocator locator = newMetaDataLocator(LOGICAL_PAGE_NAME, true);
train_getLogger(element, logger);
listener1.containingPageDidDetach();
setThrowable(t);
logger.error(contains("failed during page detach"), same(t));
listener2.containingPageDidDetach();
replay();
Page page = new PageImpl(LOGICAL_PAGE_NAME, selector, null, perThreadManager, locator);
page.setRootElement(element);
page.addLifecycleListener(listener1);
page.addLifecycleListener(listener2);
assertTrue(page.detached());
verify();
}
use of org.apache.tapestry5.internal.structure.ComponentPageElement in project tapestry-5 by apache.
the class ComponentSourceImplTest method nested_element_within_page.
@Test
public void nested_element_within_page() {
RequestPageCache cache = mockRequestPageCache();
Page page = mockPage();
ComponentPageElement element = mockComponentPageElement();
Component component = mockComponent();
ComponentClassResolver resolver = mockComponentClassResolver();
train_get(cache, PAGE_NAME, page);
train_getComponentElementByNestedId(page, NESTED_ELEMENT_ID, element);
train_getComponent(element, component);
replay();
ComponentSource source = new ComponentSourceImpl(cache, resolver, null);
assertSame(source.getComponent(PAGE_NAME + ":" + NESTED_ELEMENT_ID), component);
verify();
}
use of org.apache.tapestry5.internal.structure.ComponentPageElement 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.internal.structure.ComponentPageElement in project tapestry-5 by apache.
the class ComponentAssemblerImpl method addRootComponentMixins.
private void addRootComponentMixins(PageAssembly assembly, ComponentPageElement element) {
for (String className : instantiator.getModel().getMixinClassNames()) {
assembly.weight++;
Instantiator mixinInstantiator = instantiatorSource.getInstantiator(className);
ComponentModel model = instantiator.getModel();
element.addMixin(InternalUtils.lastTerm(className), mixinInstantiator, model.getOrderForMixin(className));
}
}
Aggregations