use of org.apache.tapestry5.FieldTranslator in project tapestry-5 by apache.
the class ComponentDefaultProviderImplTest method default_translator.
@Test
public void default_translator() {
ComponentResources resources = mockComponentResources();
FieldTranslator translator = mockFieldTranslator();
FieldTranslatorSource source = newMock(FieldTranslatorSource.class);
train_createDefaultTranslator(source, resources, "object", translator);
replay();
ComponentDefaultProvider provider = new ComponentDefaultProviderImpl(null, null, null, source, null);
assertSame(provider.defaultTranslator("object", resources), translator);
verify();
}
use of org.apache.tapestry5.FieldTranslator in project tapestry-5 by apache.
the class FieldTranslatorSourceImpl method createDefaultTranslator.
public FieldTranslator createDefaultTranslator(ComponentResources resources, String parameterName) {
assert resources != null;
assert InternalUtils.isNonBlank(parameterName);
Field field = (Field) resources.getComponent();
Class propertyType = resources.getBoundType(parameterName);
return createDefaultTranslator(field, resources.getId(), resources.getContainerMessages(), null, propertyType, resources.getAnnotationProvider(parameterName));
}
use of org.apache.tapestry5.FieldTranslator in project tapestry-5 by apache.
the class FieldTranslatorSourceImpl method createTranslator.
public FieldTranslator createTranslator(ComponentResources resources, String translatorName) {
assert resources != null;
assert InternalUtils.isNonBlank(translatorName);
Field field = (Field) resources.getComponent();
Translator translator = translatorSource.get(translatorName);
return createTranslator(field, resources.getId(), resources.getContainerMessages(), null, translator);
}
use of org.apache.tapestry5.FieldTranslator in project tapestry-5 by apache.
the class PropertyEditor method setupEnvironment.
/**
* Creates a {@link org.apache.tapestry5.services.PropertyEditContext} and pushes it onto the {@link
* org.apache.tapestry5.services.Environment} stack.
*/
void setupEnvironment(final String propertyName) {
propertyModel = model.get(propertyName);
PropertyEditContext context = new PropertyEditContext() {
public Messages getContainerMessages() {
return overrides.getOverrideMessages();
}
public String getLabel() {
return propertyModel.getLabel();
}
public String getPropertyId() {
return propertyModel.getId();
}
public Class getPropertyType() {
return propertyModel.getPropertyType();
}
public Object getPropertyValue() {
return propertyModel.getConduit().get(object);
}
public FieldTranslator getTranslator(Field field) {
return fieldTranslatorSource.createDefaultTranslator(field, propertyName, overrides.getOverrideMessages(), locale, propertyModel.getPropertyType(), propertyModel.getConduit());
}
public FieldValidator getValidator(Field field) {
return fieldValidatorDefaultSource.createDefaultValidator(field, propertyName, overrides.getOverrideMessages(), locale, propertyModel.getPropertyType(), propertyModel.getConduit());
}
public void setPropertyValue(Object value) {
propertyModel.getConduit().set(object, value);
}
public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
return propertyModel.getAnnotation(annotationClass);
}
};
environment.push(PropertyEditContext.class, context);
BeanValidationContext beanValidationContext = environment.peek(BeanValidationContext.class);
if (beanValidationContext != null) {
beanValidationContext.setCurrentProperty(propertyName);
}
heartbeat.begin();
}
use of org.apache.tapestry5.FieldTranslator in project tapestry-5 by apache.
the class FieldTranslatorSourceImplTest method create_default_translator_with_name_and_null_key.
@Test
public void create_default_translator_with_name_and_null_key() {
Field field = mockField();
Messages messages = mockMessages();
Locale locale = Locale.ENGLISH;
Class propertyType = Map.class;
TranslatorSource ts = mockTranslatorSource();
FormSupport fs = mockFormSupport();
Translator translator = mockTranslator("maptrans", Map.class);
Messages globalMessages = mockMessages();
MessageFormatter formatter = mockMessageFormatter();
MarkupWriter writer = mockMarkupWriter();
String label = "Field Label";
String message = "Woops, did it again.";
AnnotationProvider ap = mockAnnotationProvider(null);
train_findByType(ts, propertyType, translator);
train_getFormValidationId(fs, "myform");
train_contains(messages, "myform-myfield-maptrans-message", false);
train_contains(messages, "myfield-maptrans-message", false);
train_getMessageKey(translator, null);
train_getMessageFormatter(globalMessages, "maptrans-message", formatter);
train_getLabel(field, label);
train_format(formatter, message, label);
translator.render(field, message, writer, fs);
replay();
FieldTranslatorSource source = new FieldTranslatorSourceImpl(ts, globalMessages, fs);
FieldTranslator ft = source.createDefaultTranslator(field, "myfield", messages, locale, propertyType, ap);
assertEquals(ft.getType(), Map.class);
ft.render(writer);
verify();
}
Aggregations