use of org.apache.tapestry5.beaneditor.Validate in project tapestry-5 by apache.
the class RequiredTest method blank_value.
@Test
public void blank_value() {
MessageFormatter formatter = mockMessageFormatter();
Field field = mockFieldWithLabel("My Field");
train_format(formatter, "{message}", "My Field");
Html5Support html5Support = mockHtml5Support();
replay();
try {
new Required(null, html5Support).validate(field, null, formatter, "");
unreachable();
} catch (ValidationException ex) {
assertEquals(ex.getMessage(), "{message}");
}
verify();
}
use of org.apache.tapestry5.beaneditor.Validate in project tapestry-5 by apache.
the class RequiredTest method empty_collection_value.
@Test
public void empty_collection_value() {
MessageFormatter formatter = mockMessageFormatter();
Field field = mockFieldWithLabel("My Field");
train_format(formatter, "{message}", "My Field");
Html5Support html5Support = mockHtml5Support();
replay();
try {
new Required(null, html5Support).validate(field, null, formatter, Arrays.asList());
unreachable();
} catch (ValidationException ex) {
assertEquals(ex.getMessage(), "{message}");
}
verify();
}
use of org.apache.tapestry5.beaneditor.Validate in project tapestry-5 by apache.
the class RequiredTest method non_blank_value.
@Test
public void non_blank_value() throws Exception {
MessageFormatter formatter = mockMessageFormatter();
Field field = mockField();
Html5Support html5Support = mockHtml5Support();
replay();
new Required(null, html5Support).validate(field, null, formatter, "not null");
verify();
}
use of org.apache.tapestry5.beaneditor.Validate in project tapestry-5 by apache.
the class RequiredTest method not_empty_collection_value.
@Test
public void not_empty_collection_value() throws Exception {
MessageFormatter formatter = mockMessageFormatter();
Field field = mockField();
Html5Support html5Support = mockHtml5Support();
replay();
new Required(null, html5Support).validate(field, null, formatter, Arrays.asList("A", "B"));
verify();
}
use of org.apache.tapestry5.beaneditor.Validate 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();
}
Aggregations