use of org.apache.tapestry5.ValidationException 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.ValidationException 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.ValidationException in project tapestry-5 by apache.
the class Select method onChange.
Object onChange(final EventContext context, @RequestParameter(value = "t:selectvalue", allowBlank = true) final String selectValue) throws ValidationException {
final Object newValue = toValue(selectValue);
CaptureResultCallback<Object> callback = new CaptureResultCallback<Object>();
EventContext newContext = new AbstractEventContext() {
@Override
public int getCount() {
return context.getCount() + 1;
}
@Override
public <T> T get(Class<T> desiredType, int index) {
if (index == 0) {
return typeCoercer.coerce(newValue, desiredType);
}
return context.get(desiredType, index - 1);
}
};
this.resources.triggerContextEvent(EventConstants.VALUE_CHANGED, newContext, callback);
this.value = newValue;
return callback.getResult();
}
use of org.apache.tapestry5.ValidationException in project tapestry-5 by apache.
the class Palette method processSubmission.
@Override
protected void processSubmission(String controlName) {
String parameterValue = request.getParameter(controlName);
JSONArray values = new JSONArray(parameterValue);
// Use a couple of local variables to cut down on access via bindings
Collection<Object> selected = this.selected;
selected.clear();
ValueEncoder encoder = this.encoder;
// TODO: Validation error if the model does not contain a value.
int count = values.length();
for (int i = 0; i < count; i++) {
String value = values.getString(i);
Object objectValue = encoder.toValue(value);
selected.add(objectValue);
}
putPropertyNameIntoBeanValidationContext("selected");
try {
fieldValidationSupport.validate(selected, resources, validate);
this.selected = selected;
} catch (final ValidationException e) {
validationTracker.recordError(this, e.getMessage());
}
removePropertyNameFromBeanValidationContext();
}
use of org.apache.tapestry5.ValidationException in project tapestry-5 by apache.
the class Upload method processSubmission.
@SuppressWarnings({ "unchecked" })
@Override
protected void processSubmission(String controlName) {
UploadedFile uploaded = decoder.getFileUpload(controlName);
if (uploaded != null && (uploaded.getFileName() == null || uploaded.getFileName().length() == 0)) {
uploaded = null;
}
try {
fieldValidationSupport.validate(uploaded, resources, validate);
} catch (ValidationException ex) {
validationTracker.recordError(this, ex.getMessage());
}
value = uploaded;
}
Aggregations