Search in sources :

Example 16 with Environment

use of org.apache.tapestry5.services.Environment in project tapestry-5 by apache.

the class MessagesAnnotationConstraintGeneratorTest method single_constraint.

@Test
public void single_constraint() {
    Environment e = getService(Environment.class);
    pushAndTrainEnvironmentalObjects(e, true, "required");
    MessagesConstraintGenerator gen = new MessagesConstraintGenerator(e);
    assertEquals(gen.buildConstraints(null, null), Arrays.asList("required"));
}
Also used : Environment(org.apache.tapestry5.services.Environment) Test(org.testng.annotations.Test)

Example 17 with Environment

use of org.apache.tapestry5.services.Environment in project tapestry-5 by apache.

the class MessagesAnnotationConstraintGeneratorTest method multiple_constraints.

@Test
public void multiple_constraints() {
    Environment e = getService(Environment.class);
    pushAndTrainEnvironmentalObjects(e, true, "required,minlength=3,regexp=^([a-zA-Z0-9]{2,4})+@(\\p{Lower})*$");
    MessagesConstraintGenerator gen = new MessagesConstraintGenerator(e);
    assertEquals(gen.buildConstraints(null, null), Arrays.asList("required", "minlength=3", "regexp=^([a-zA-Z0-9]{2,4})+@(\\p{Lower})*$"));
}
Also used : Environment(org.apache.tapestry5.services.Environment) Test(org.testng.annotations.Test)

Example 18 with Environment

use of org.apache.tapestry5.services.Environment in project tapestry-5 by apache.

the class MessagesAnnotationConstraintGeneratorTest method no_property.

@Test
public void no_property() {
    Environment e = getService(Environment.class);
    pushAndTrainEnvironmentalObjects(e, false, null);
    MessagesConstraintGenerator gen = new MessagesConstraintGenerator(e);
    assertNull(gen.buildConstraints(null, null));
    pop(e);
    verify();
}
Also used : Environment(org.apache.tapestry5.services.Environment) Test(org.testng.annotations.Test)

Example 19 with Environment

use of org.apache.tapestry5.services.Environment in project tapestry-5 by apache.

the class MessagesAnnotationConstraintGeneratorTest method empty_message.

@Test
public void empty_message() {
    Environment e = getService(Environment.class);
    pushAndTrainEnvironmentalObjects(e, true, "");
    MessagesConstraintGenerator gen = new MessagesConstraintGenerator(e);
    assertNull(gen.buildConstraints(null, null));
    pop(e);
    verify();
}
Also used : Environment(org.apache.tapestry5.services.Environment) Test(org.testng.annotations.Test)

Example 20 with Environment

use of org.apache.tapestry5.services.Environment 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

Environment (org.apache.tapestry5.services.Environment)17 Test (org.testng.annotations.Test)17 ComponentResources (org.apache.tapestry5.ComponentResources)6 Messages (org.apache.tapestry5.commons.Messages)6 PropertyOverrides (org.apache.tapestry5.PropertyOverrides)5 BeanModelSource (org.apache.tapestry5.beanmodel.services.BeanModelSource)5 BeanModel (org.apache.tapestry5.beanmodel.BeanModel)4 Location (org.apache.tapestry5.commons.Location)4 RegistrationData (org.apache.tapestry5.integration.app1.data.RegistrationData)3 BeanEditContext (org.apache.tapestry5.services.BeanEditContext)3 Annotation (java.lang.annotation.Annotation)2 FieldValidator (org.apache.tapestry5.FieldValidator)2 TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)2 UnknownValueException (org.apache.tapestry5.commons.util.UnknownValueException)2 BeanValidationContext (org.apache.tapestry5.internal.BeanValidationContext)2 BeanValidationContextImpl (org.apache.tapestry5.internal.BeanValidationContextImpl)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Locale (java.util.Locale)1 Map (java.util.Map)1 NoSuchElementException (java.util.NoSuchElementException)1