use of org.apache.tapestry5.annotations.Component in project tapestry-5 by apache.
the class UploadTest method process_submission_ignores_null_value.
@SuppressWarnings({ "unchecked" })
@Test
public void process_submission_ignores_null_value() throws Exception {
MultipartDecoder decoder = mockMultipartDecoder();
UploadedFile uploadedFile = mockUploadedFile();
ComponentResources resources = mockComponentResources();
FieldValidationSupport support = mockFieldValidationSupport();
FieldValidator validate = mockFieldValidator();
Upload component = new Upload(null, validate, decoder, null, resources, support);
expect(decoder.getFileUpload("test")).andReturn(uploadedFile);
expect(uploadedFile.getFileName()).andReturn("").atLeastOnce();
support.validate(null, resources, validate);
replay();
component.processSubmission("test");
verify();
assertNull(component.getValue());
}
use of org.apache.tapestry5.annotations.Component in project tapestry-5 by apache.
the class UploadTest method validation_decorator_invoked_inside_begin_render.
@Test
public void validation_decorator_invoked_inside_begin_render() throws Exception {
getMocksControl().checkOrder(true);
ComponentResources resources = mockComponentResources();
Upload component = new Upload(null, null, null, null, resources, null);
MarkupWriter writer = createMarkupWriter();
writer.element("form");
FieldValidator validator = mockFieldValidator();
Request request = mockRequest();
FormSupport formSupport = mockFormSupport();
formSupport.setEncodingType(Upload.MULTIPART_ENCTYPE);
component.injectFormSupport(formSupport).injectRequest(request);
ValidationDecorator decorator = mockValidationDecorator();
component.injectDecorator(decorator).injectFieldValidator(validator);
validator.render(writer);
resources.renderInformalParameters(writer);
decorator.insideField(component);
train_isXHR(request, false);
replay();
component.beginRender(writer);
verify();
}
use of org.apache.tapestry5.annotations.Component in project tapestry-5 by apache.
the class UploadTest method process_submission_tracks_validator_errors.
@SuppressWarnings({ "unchecked", "ThrowableInstanceNeverThrown" })
@Test
public void process_submission_tracks_validator_errors() throws Exception {
MultipartDecoder decoder = mockMultipartDecoder();
UploadedFile uploadedFile = mockUploadedFile();
FieldValidator<Object> validate = mockFieldValidator();
ValidationTracker tracker = mockValidationTracker();
ComponentResources resources = mockComponentResources();
FieldValidationSupport support = mockFieldValidationSupport();
Upload component = new Upload(null, validate, decoder, tracker, resources, support);
expect(decoder.getFileUpload("test")).andReturn(uploadedFile);
expect(uploadedFile.getFileName()).andReturn("test").atLeastOnce();
support.validate(uploadedFile, resources, validate);
expectLastCall().andThrow(new ValidationException("an error"));
tracker.recordError(component, "an error");
replay();
component.processSubmission("test");
verify();
}
use of org.apache.tapestry5.annotations.Component in project tapestry-5 by apache.
the class BindingSourceImpl method newBinding.
public Binding newBinding(String description, ComponentResources container, ComponentResources component, String defaultPrefix, String expression, Location location) {
assert InternalUtils.isNonBlank(description);
assert container != null;
assert InternalUtils.isNonBlank(defaultPrefix);
assert component != null;
// TAP5-845: The expression may be the empty string. This is ok, if it's compatible with
// the default prefix (the empty string is not a valid property expression, but is valid
// as a literal string, perhaps as an informal parameter).
// Location might be null
String subexpression = expression;
int colonx = expression.indexOf(':');
BindingFactory factory = null;
if (colonx > 0) {
String prefix = expression.substring(0, colonx);
factory = factories.get(prefix);
if (factory != null)
subexpression = expression.substring(colonx + 1);
}
if (factory == null)
factory = factories.get(defaultPrefix);
try {
return factory.newBinding(interner.intern(description), container, component, subexpression, location);
} catch (Exception ex) {
throw new TapestryException(String.format("Could not convert '%s' into a component parameter binding: %s", expression, ExceptionUtils.toMessage(ex)), location, ex);
}
}
use of org.apache.tapestry5.annotations.Component in project tapestry-5 by apache.
the class AjaxComponentInstanceEventResultProcessor method processResultValue.
public void processResultValue(Component value) throws IOException {
ComponentResources resources = value.getComponentResources();
boolean isPage = value == resources.getPage();
String pageName = resources.getPageName();
if (isPage) {
// This will ultimately send a JSON response to redirect to the page
masterProcessor.processResultValue(pageName);
return;
}
// Otherwise, a component within a page. Components are transformed to implement RenderCommand, but if we just
// pass the component itself to the master processor, we'll get in a loop, so we instead
// pass the ComponentPageElement (which implements RenderCommand as well).
Page page = cache.get(pageName);
String nestedId = resources.getNestedId();
RenderCommand command = page.getComponentElementByNestedId(nestedId);
masterProcessor.processResultValue(command);
}
Aggregations