use of org.apache.tapestry5.commons.internal.util.TapestryException in project tapestry-5 by apache.
the class BeanEditor method doPrepare.
/**
* Used to initialize the model if necessary, to instantiate the object being edited if necessary, and to push the
* BeanEditContext into the environment.
*/
void doPrepare() {
if (model == null) {
Class type = resources.getBoundType("object");
model = modelSource.createEditModel(type, overrides.getOverrideMessages());
BeanModelUtils.modify(model, add, include, exclude, reorder);
}
if (object == null) {
try {
object = model.newInstance();
} catch (Exception ex) {
String message = String.format("Exception instantiating instance of %s (for component '%s'): %s", PlasticUtils.toTypeName(model.getBeanType()), resources.getCompleteId(), ex);
throw new TapestryException(message, resources.getLocation(), ex);
}
}
BeanEditContext context = new BeanEditContextImpl(model.getBeanType());
cachedObject = object;
environment.push(BeanEditContext.class, context);
// TAP5-2101: Always provide a new BeanValidationContext
environment.push(BeanValidationContext.class, new BeanValidationContextImpl(object));
}
use of org.apache.tapestry5.commons.internal.util.TapestryException in project tapestry-5 by apache.
the class AbstractPropertyOutputTest method test_null_pointer_exception_message.
@Test
public // Tests TAPESTRY-2182.
void test_null_pointer_exception_message() {
final PropertyConduit conduit = mockPropertyConduit();
final PropertyModel model = mockPropertyModel();
final Object object = new Object();
ComponentResources resources = mockComponentResources();
Location location = mockLocation();
propertyOutputFixture.inject(model, object, resources);
expect(model.getConduit()).andReturn(conduit);
expect(conduit.get(object)).andThrow(new NullPointerException());
expect(model.getPropertyName()).andReturn("wilma.occupation.address");
expect(resources.getLocation()).andReturn(location);
replay();
try {
propertyOutputFixture.readPropertyForObject();
fail("Expected a NullPointerException to be thrown.");
} catch (final TapestryException ex) {
assertEquals(ex.getMessage(), "Property 'wilma.occupation.address' contains a null value in the path.");
assertSame(ex.getLocation(), location);
assertTrue(ex.getCause() instanceof NullPointerException);
}
verify();
}
use of org.apache.tapestry5.commons.internal.util.TapestryException 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.commons.internal.util.TapestryException in project tapestry-5 by apache.
the class ComponentAssemblerImpl method createEmbeddedAssembler.
public EmbeddedComponentAssembler createEmbeddedAssembler(String embeddedId, String componentClassName, EmbeddedComponentModel embeddedModel, String mixins, Location location) {
try {
if (InternalUtils.isBlank(componentClassName)) {
throw new TapestryException("You must specify the type via t:type, the element, or @Component annotation.", location, null);
}
EmbeddedComponentAssemblerImpl embedded = new EmbeddedComponentAssemblerImpl(assemblerSource, instantiatorSource, componentClassResolver, componentClassName, getSelector(), embeddedModel, mixins, location, strictMixinParameters);
if (embeddedIdToAssembler == null)
embeddedIdToAssembler = CollectionFactory.newMap();
embeddedIdToAssembler.put(embeddedId, embedded);
if (embeddedModel != null) {
for (String publishedParameterName : embeddedModel.getPublishedParameters()) {
if (publishedParameterToEmbeddedId == null)
publishedParameterToEmbeddedId = CollectionFactory.newCaseInsensitiveMap();
String existingEmbeddedId = publishedParameterToEmbeddedId.get(publishedParameterName);
if (existingEmbeddedId != null) {
throw new TapestryException(String.format("Parameter '%s' of embedded component '%s' can not be published as a parameter of component %s, as it has previously been published by embedded component '%s'.", publishedParameterName, embeddedId, instantiator.getModel().getComponentClassName(), existingEmbeddedId), location, null);
}
publishedParameterToEmbeddedId.put(publishedParameterName, embeddedId);
}
}
return embedded;
} catch (Exception ex) {
throw new TapestryException(String.format("Failure creating embedded component '%s' of %s: %s", embeddedId, instantiator.getModel().getComponentClassName(), ExceptionUtils.toMessage(ex)), location, ex);
}
}
use of org.apache.tapestry5.commons.internal.util.TapestryException in project tapestry-5 by apache.
the class EmbeddedComponentAssemblerImpl method addMixin.
private void addMixin(String className, String... order) {
Instantiator mixinInstantiator = instantiatorSource.getInstantiator(className);
String mixinId = InternalUtils.lastTerm(className);
if (mixinIdToInstantiator.containsKey(mixinId))
throw new TapestryException(String.format("Mixins applied to a component must be unique. Mixin '%s' has already been applied.", mixinId), location, null);
mixinIdToInstantiator.put(mixinId, mixinInstantiator);
mixinsIdToOrderConstraints.put(mixinId, order);
}
Aggregations