use of org.apache.tapestry5.beaneditor.Validate 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.beaneditor.Validate in project tapestry-5 by apache.
the class FieldValidatorDefaultSourceImplTest method invokes_all_constraint_generators.
@SuppressWarnings("unchecked")
@Test
public void invokes_all_constraint_generators() throws Exception {
getMocksControl().checkOrder(true);
ValidationConstraintGenerator gen = mockValidationConstraintGenerator();
FieldValidator fv1 = mockFieldValidator();
FieldValidator fv2 = mockFieldValidator();
FieldValidatorSource source = mockFieldValidatorSource();
Class propertyType = Integer.class;
AnnotationProvider provider = mockAnnotationProvider();
String overrideId = "overrideId";
Messages overrideMessages = mockMessages();
Field field = mockField();
Locale locale = Locale.ENGLISH;
String value = "*VALUE*";
train_buildConstraints(gen, propertyType, provider, "cons1", "cons2");
train_createValidator(source, field, "cons1", null, overrideId, overrideMessages, locale, fv1);
train_createValidator(source, field, "cons2", null, overrideId, overrideMessages, locale, fv2);
fv1.validate(value);
fv2.validate(value);
replay();
FieldValidatorDefaultSource fieldValidatorSource = new FieldValidatorDefaultSourceImpl(gen, source);
FieldValidator composite = fieldValidatorSource.createDefaultValidator(field, overrideId, overrideMessages, locale, propertyType, provider);
composite.validate(value);
verify();
}
use of org.apache.tapestry5.beaneditor.Validate in project tapestry-5 by apache.
the class ClientDataEncoderImpl method decodeClientData.
public ObjectInputStream decodeClientData(String clientData) {
// The clientData is Base64 that's been gzip'ed (i.e., this matches
// what ClientDataSinkImpl does).
int colonx = clientData.indexOf(':');
if (colonx < 0) {
throw new IllegalArgumentException("Client data must be prefixed with its HMAC code.");
}
// Extract the string presumably encoded by the server using the secret key.
String storedHmacResult = clientData.substring(0, colonx);
String clientStream = clientData.substring(colonx + 1);
try {
Base64InputStream b64in = new Base64InputStream(clientStream);
validateHMAC(storedHmacResult, b64in);
// After reading it once to validate, reset it for the actual read (which includes the GZip decompression).
b64in.reset();
BufferedInputStream buffered = new BufferedInputStream(new GZIPInputStream(b64in));
return new ObjectInputStream(buffered);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
use of org.apache.tapestry5.beaneditor.Validate in project tapestry-5 by apache.
the class ValidateBindingFactory method newBinding.
public Binding newBinding(String description, ComponentResources container, ComponentResources component, final String expression, Location location) {
Object fieldAsObject = component.getComponent();
if (!Field.class.isInstance(fieldAsObject))
throw new TapestryException(String.format("Component '%s' is not a field (it does not implement the Field interface) and may not be used with the validate: binding prefix.", component.getCompleteId()), location, null);
final Field field = (Field) fieldAsObject;
return new InvariantBinding(location, FieldValidator.class, interner.intern(description + ": " + expression)) {
public Object get() {
return fieldValidatorSource.createValidators(field, expression);
}
};
}
use of org.apache.tapestry5.beaneditor.Validate in project tapestry-5 by apache.
the class MessagesConstraintGenerator method buildConstraints.
public List<String> buildConstraints(Class propertyType, AnnotationProvider annotationProvider) {
EnvironmentMessages environmentMessages = environment.peek(EnvironmentMessages.class);
if (environmentMessages == null) {
return null;
}
String key = environmentMessages.getOverrideId() + "-validate";
Messages m = environmentMessages.getMessages();
if (!m.contains(key)) {
return null;
}
String result = m.get(key);
if (InternalUtils.isBlank(result)) {
return null;
}
return Arrays.asList(splitPattern.split(result));
}
Aggregations