Search in sources :

Example 1 with EnvironmentMessages

use of org.apache.tapestry5.internal.beaneditor.EnvironmentMessages in project tapestry-5 by apache.

the class MessagesAnnotationConstraintGeneratorTest method pushAndTrainEnvironmentalObjects.

private void pushAndTrainEnvironmentalObjects(Environment e, boolean hasProperty, String propertyValue) {
    Messages messages = mockMessages();
    train_contains(messages, "testProperty-validate", hasProperty);
    if (hasProperty) {
        train_get(messages, "testProperty-validate", propertyValue);
    }
    EnvironmentMessages em = new EnvironmentMessages(messages, "testProperty");
    e.push(EnvironmentMessages.class, em);
    replay();
}
Also used : Messages(org.apache.tapestry5.commons.Messages)

Example 2 with EnvironmentMessages

use of org.apache.tapestry5.internal.beaneditor.EnvironmentMessages 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));
}
Also used : Messages(org.apache.tapestry5.commons.Messages)

Example 3 with EnvironmentMessages

use of org.apache.tapestry5.internal.beaneditor.EnvironmentMessages in project tapestry-5 by apache.

the class TapestryModule method decorateFieldValidatorDefaultSource.

/**
 * Decorate FieldValidatorDefaultSource to setup the EnvironmentMessages
 * object and place it in the environment.
 * Although this could have been implemented directly in the default
 * implementation of the service, doing it
 * as service decoration ensures that the environment will be properly setup
 * even if a user overrides the default
 * service implementation.
 *
 * @param defaultSource
 *         The service to decorate
 * @param environment
 */
public static FieldValidatorDefaultSource decorateFieldValidatorDefaultSource(final FieldValidatorDefaultSource defaultSource, final Environment environment) {
    return new FieldValidatorDefaultSource() {

        public FieldValidator createDefaultValidator(Field field, String overrideId, Messages overrideMessages, Locale locale, Class propertyType, AnnotationProvider propertyAnnotations) {
            environment.push(EnvironmentMessages.class, new EnvironmentMessages(overrideMessages, overrideId));
            FieldValidator fieldValidator = defaultSource.createDefaultValidator(field, overrideId, overrideMessages, locale, propertyType, propertyAnnotations);
            environment.pop(EnvironmentMessages.class);
            return fieldValidator;
        }

        public FieldValidator createDefaultValidator(ComponentResources resources, String parameterName) {
            EnvironmentMessages em = new EnvironmentMessages(resources.getContainerMessages(), resources.getId());
            environment.push(EnvironmentMessages.class, em);
            FieldValidator fieldValidator = defaultSource.createDefaultValidator(resources, parameterName);
            environment.pop(EnvironmentMessages.class);
            return fieldValidator;
        }
    };
}
Also used : PersistentLocale(org.apache.tapestry5.services.PersistentLocale) Locale(java.util.Locale) ThreadLocale(org.apache.tapestry5.ioc.services.ThreadLocale) Field(org.apache.tapestry5.Field) ComponentMessages(org.apache.tapestry5.services.ComponentMessages) EnvironmentMessages(org.apache.tapestry5.internal.beaneditor.EnvironmentMessages) Messages(org.apache.tapestry5.commons.Messages) AnnotationProvider(org.apache.tapestry5.commons.AnnotationProvider) FieldValidatorDefaultSource(org.apache.tapestry5.services.FieldValidatorDefaultSource) FieldValidator(org.apache.tapestry5.FieldValidator) EnvironmentMessages(org.apache.tapestry5.internal.beaneditor.EnvironmentMessages) ComponentResources(org.apache.tapestry5.ComponentResources)

Aggregations

Messages (org.apache.tapestry5.commons.Messages)3 Locale (java.util.Locale)1 ComponentResources (org.apache.tapestry5.ComponentResources)1 Field (org.apache.tapestry5.Field)1 FieldValidator (org.apache.tapestry5.FieldValidator)1 AnnotationProvider (org.apache.tapestry5.commons.AnnotationProvider)1 EnvironmentMessages (org.apache.tapestry5.internal.beaneditor.EnvironmentMessages)1 ThreadLocale (org.apache.tapestry5.ioc.services.ThreadLocale)1 ComponentMessages (org.apache.tapestry5.services.ComponentMessages)1 FieldValidatorDefaultSource (org.apache.tapestry5.services.FieldValidatorDefaultSource)1 PersistentLocale (org.apache.tapestry5.services.PersistentLocale)1