use of org.apache.tapestry5.ValidationDecorator 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.ValidationDecorator in project tapestry-5 by apache.
the class Form method beginRender.
void beginRender(MarkupWriter writer) {
Link link = resources.createFormEventLink(EventConstants.ACTION, context);
String actionURL = secure && secureEnabled ? link.toAbsoluteURI(true) : link.toURI();
actionSink = new ComponentActionSink(logger, clientDataEncoder);
clientId = javascriptSupport.allocateClientId(resources);
// Pre-register some names, to prevent client-side collisions with function names
// attached to the JS Form object.
IdAllocator allocator = new IdAllocator();
preallocateNames(allocator);
formSupport = createRenderTimeFormSupport(clientId, actionSink, allocator);
environment.push(FormSupport.class, formSupport);
environment.push(ValidationTracker.class, tracker);
if (autofocus) {
ValidationDecorator autofocusDecorator = new AutofocusValidationDecorator(environment.peek(ValidationDecorator.class), tracker, javascriptSupport);
environment.push(ValidationDecorator.class, autofocusDecorator);
}
// Now that the environment is setup, inform the component or other
// listeners that the form
// is about to render.
resources.triggerEvent(EventConstants.PREPARE_FOR_RENDER, context, null);
resources.triggerEvent(EventConstants.PREPARE, context, null);
// Push BeanValidationContext only after the container had a chance to prepare
environment.push(BeanValidationContext.class, new BeanValidationContextImpl(validate));
// Save the form element for later, in case we want to write an encoding
// type attribute.
form = writer.element("form", "id", clientId, "method", "post", "action", actionURL, "data-update-zone", zone, DATA_ATTRIBUTE, DATA_ATTRIBUTE_VALUE);
if (clientValidation != ClientValidation.NONE) {
writer.attributes("data-validate", "submit");
}
if (async) {
javascriptSupport.require("t5/core/zone");
writer.attributes("data-async-trigger", true);
}
resources.renderInformalParameters(writer);
div = writer.element("div");
for (String parameterName : link.getParameterNames()) {
String[] values = link.getParameterValues(parameterName);
for (String value : values) {
// but the input value shouldn't be encoded.
try {
value = URLDecoder.decode(value, "UTF-8");
} catch (UnsupportedEncodingException e) {
logger.error("Enable to decode parameter value for parameter {} in form {}", parameterName, form.getName(), e);
}
writer.element("input", "type", "hidden", "name", parameterName, "value", value);
writer.end();
}
}
// div
writer.end();
environment.peek(Heartbeat.class).begin();
}
use of org.apache.tapestry5.ValidationDecorator in project tapestry-5 by apache.
the class TapestryModule method contributeMarkupRenderer.
/**
* Adds page render filters, each of which provides an {@link org.apache.tapestry5.annotations.Environmental}
* service. Filters
* often provide {@link org.apache.tapestry5.annotations.Environmental} services needed by
* components as they render.
* <dl>
* <dt>DocumentLinker</dt>
* <dd>Provides {@link org.apache.tapestry5.internal.services.DocumentLinker}</dd>
* <dt>ClientBehaviorSupport (deprecated in 5.4)</dt>
* <dd>Provides {@link ClientBehaviorSupport}</dd>
* <dt>Heartbeat</dt>
* <dd>Provides {@link org.apache.tapestry5.services.Heartbeat}</dd>
* <dt>ValidationDecorator (deprecated in 5.4)</dt>
* <dd>Provides {@link org.apache.tapestry5.ValidationDecorator} (via {@link ValidationDecoratorFactory#newInstance(org.apache.tapestry5.MarkupWriter)})</dd>
* <dt>PageNameMeta (since 5.4)</dt>
* <dd>Renders a {@code <meta/>} tag describing the active page name (development mode only)</dd>
* <dt>ImportCoreStack (since 5.4) </dt>
* <dd>Imports the "core" stack (necessary to get the Bootstrap CSS, if nothing else).</dd>
* </dl>
*
* @see org.apache.tapestry5.SymbolConstants#OMIT_GENERATOR_META
* @see org.apache.tapestry5.http.TapestryHttpSymbolConstants#PRODUCTION_MODE
* @see org.apache.tapestry5.SymbolConstants#INCLUDE_CORE_STACK
* @see org.apache.tapestry5.SymbolConstants#ENABLE_PAGELOADING_MASK
*/
public void contributeMarkupRenderer(OrderedConfiguration<MarkupRendererFilter> configuration, final ModuleManager moduleManager, @Symbol(SymbolConstants.OMIT_GENERATOR_META) final boolean omitGeneratorMeta, @Symbol(TapestryHttpConstants.TAPESTRY_VERSION) final String tapestryVersion, @Symbol(TapestryHttpSymbolConstants.PRODUCTION_MODE) boolean productionMode, @Symbol(SymbolConstants.INCLUDE_CORE_STACK) final boolean includeCoreStack, @Symbol(SymbolConstants.ENABLE_PAGELOADING_MASK) final boolean enablePageloadingMask, final ValidationDecoratorFactory validationDecoratorFactory) {
MarkupRendererFilter documentLinker = new MarkupRendererFilter() {
public void renderMarkup(MarkupWriter writer, MarkupRenderer renderer) {
DocumentLinkerImpl linker = new DocumentLinkerImpl(moduleManager, omitGeneratorMeta, enablePageloadingMask, tapestryVersion);
environment.push(DocumentLinker.class, linker);
renderer.renderMarkup(writer);
environment.pop(DocumentLinker.class);
linker.updateDocument(writer.getDocument());
}
};
MarkupRendererFilter clientBehaviorSupport = new MarkupRendererFilter() {
public void renderMarkup(MarkupWriter writer, MarkupRenderer renderer) {
ClientBehaviorSupportImpl clientBehaviorSupport = new ClientBehaviorSupportImpl();
environment.push(ClientBehaviorSupport.class, clientBehaviorSupport);
renderer.renderMarkup(writer);
environment.pop(ClientBehaviorSupport.class);
}
};
MarkupRendererFilter heartbeat = new MarkupRendererFilter() {
public void renderMarkup(MarkupWriter writer, MarkupRenderer renderer) {
Heartbeat heartbeat = new HeartbeatImpl();
heartbeat.begin();
environment.push(Heartbeat.class, heartbeat);
renderer.renderMarkup(writer);
environment.pop(Heartbeat.class);
heartbeat.end();
}
};
MarkupRendererFilter defaultValidationDecorator = new MarkupRendererFilter() {
public void renderMarkup(MarkupWriter writer, MarkupRenderer renderer) {
ValidationDecorator decorator = validationDecoratorFactory.newInstance(writer);
environment.push(ValidationDecorator.class, decorator);
renderer.renderMarkup(writer);
environment.pop(ValidationDecorator.class);
}
};
MarkupRendererFilter importCoreStack = new MarkupRendererFilter() {
public void renderMarkup(MarkupWriter writer, MarkupRenderer renderer) {
renderer.renderMarkup(writer);
environment.peekRequired(JavaScriptSupport.class).importStack(InternalConstants.CORE_STACK_NAME);
}
};
configuration.add("DocumentLinker", documentLinker);
configuration.add("ClientBehaviorSupport", clientBehaviorSupport, "after:JavaScriptSupport");
configuration.add("Heartbeat", heartbeat);
configuration.add("ValidationDecorator", defaultValidationDecorator);
if (includeCoreStack) {
configuration.add("ImportCoreStack", importCoreStack);
}
if (productionMode) {
configuration.add("PageNameMeta", null);
} else {
configuration.addInstance("PageNameMeta", PageNameMetaInjector.class);
}
}
use of org.apache.tapestry5.ValidationDecorator in project tapestry-5 by apache.
the class UploadTest method begin_render_invokes_field_validator.
@SuppressWarnings("unchecked")
@Test
public void begin_render_invokes_field_validator() throws Exception {
getMocksControl().checkOrder(true);
FieldValidator<Object> validate = mockFieldValidator();
ComponentResources resources = mockComponentResources();
Upload component = new Upload(null, validate, null, null, resources, null);
MarkupWriter writer = createMarkupWriter();
writer.element("form");
Request request = mockRequest();
FormSupport formSupport = mockFormSupport();
formSupport.setEncodingType(Upload.MULTIPART_ENCTYPE);
ValidationDecorator decorator = mockValidationDecorator();
component.injectDecorator(decorator).injectRequest(request).injectFormSupport(formSupport);
validate.render(writer);
resources.renderInformalParameters(writer);
decorator.insideField(component);
train_isXHR(request, false);
replay();
component.beginRender(writer);
verify();
}
use of org.apache.tapestry5.ValidationDecorator in project tapestry-5 by apache.
the class OverrideValidationDecorator method beginRender.
void beginRender(MarkupWriter writer) {
ValidationDecorator existing = environment.peekRequired(ValidationDecorator.class);
environment.push(ValidationDecorator.class, new ChattyValidationDecorator(writer, existing));
}
Aggregations