Search in sources :

Example 1 with Messages

use of org.apache.tapestry5.commons.Messages in project tapestry-5 by apache.

the class MessagesSourceImpl method getMessages.

public Messages getMessages(MessagesBundle bundle, ComponentResourceSelector selector) {
    MultiKey key = new MultiKey(bundle.getId(), selector);
    Messages result = messagesByBundleIdAndSelector.get(key);
    if (result == null) {
        result = buildMessages(bundle, selector);
        messagesByBundleIdAndSelector.put(key, result);
    }
    return result;
}
Also used : Messages(org.apache.tapestry5.commons.Messages) MultiKey(org.apache.tapestry5.commons.util.MultiKey)

Example 2 with Messages

use of org.apache.tapestry5.commons.Messages in project tapestry-5 by apache.

the class ComponentDefaultProviderImplTest method default_label_key_missing.

@Test
public void default_label_key_missing() {
    ComponentResources resources = mockComponentResources();
    ComponentResources container = mockComponentResources();
    Messages messages = mockMessages();
    String componentId = "myField";
    String key = componentId + "-label";
    train_getId(resources, componentId);
    train_getContainerResources(resources, container);
    train_getMessages(container, messages);
    train_contains(messages, key, false);
    replay();
    ComponentDefaultProvider provider = new ComponentDefaultProviderImpl(null, null, null, null, null);
    assertEquals(provider.defaultLabel(resources), "My Field");
    verify();
}
Also used : Messages(org.apache.tapestry5.commons.Messages) ComponentResources(org.apache.tapestry5.ComponentResources) ComponentDefaultProvider(org.apache.tapestry5.services.ComponentDefaultProvider) Test(org.testng.annotations.Test)

Example 3 with Messages

use of org.apache.tapestry5.commons.Messages in project tapestry-5 by apache.

the class AbstractBeanModelSourceImplTest method sortable_annotation.

// https://issues.apache.org/jira/browse/TAP5-2305
@Test
public void sortable_annotation() {
    Messages messages = mockMessages();
    stub_contains(messages, false);
    replay();
    BeanModel<SortableBean> model = source.createDisplayModel(SortableBean.class, messages);
    model.add("nonSortableByDefault");
    model.add("sortable");
    // checking whether non-@Sortable annotated properties still behave in the old ways
    assertTrue(model.get("sortableByDefault").isSortable());
    assertFalse(model.get("nonSortableByDefault").isSortable());
    // checking @Sortable itself
    assertFalse(model.get("nonSortable").isSortable());
    assertTrue(model.get("sortable").isSortable());
    verify();
}
Also used : Messages(org.apache.tapestry5.commons.Messages) Test(org.testng.annotations.Test)

Example 4 with Messages

use of org.apache.tapestry5.commons.Messages in project tapestry-5 by apache.

the class AbstractBeanModelSourceImplTest method edit_property_label.

@Test
public void edit_property_label() {
    Messages messages = mockMessages();
    stub_contains(messages, false);
    replay();
    BeanModel model = source.create(SimpleBean.class, true, messages).get("age").label("Decrepitude").model();
    assertEquals(model.get("age").getLabel(), "Decrepitude");
    verify();
}
Also used : Messages(org.apache.tapestry5.commons.Messages) BeanModel(org.apache.tapestry5.beanmodel.BeanModel) Test(org.testng.annotations.Test)

Example 5 with Messages

use of org.apache.tapestry5.commons.Messages in project tapestry-5 by apache.

the class AbstractBeanModelSourceImplTest method composite_bean.

@Test
public void composite_bean() {
    Messages messages = mockMessages();
    stub_contains(messages, false);
    train_contains(messages, "simpleage-label", true);
    train_get(messages, "simpleage-label", "Years of Age");
    replay();
    BeanModel model = source.create(CompositeBean.class, true, messages);
    // No editor for CompositeBean, so this will be empty.
    assertEquals(model.getPropertyNames(), Collections.emptyList());
    // There's not editor for string arrays yet, so it won't show up normally.
    PropertyModel firstName = model.add("simple.firstName");
    assertEquals(firstName.getLabel(), "First Name");
    PropertyModel age = model.add("simple.age");
    assertEquals(age.getLabel(), "Years of Age");
    CompositeBean bean = new CompositeBean();
    firstName.getConduit().set(bean, "Fred");
    age.getConduit().set(bean, "97");
    assertEquals(bean.getSimple().getFirstName(), "Fred");
    assertEquals(bean.getSimple().getAge(), 97);
    bean.getSimple().setAge(24);
    assertEquals(age.getConduit().get(bean), new Integer(24));
    verify();
}
Also used : Messages(org.apache.tapestry5.commons.Messages) BeanModel(org.apache.tapestry5.beanmodel.BeanModel) PropertyModel(org.apache.tapestry5.beanmodel.PropertyModel) Test(org.testng.annotations.Test)

Aggregations

Messages (org.apache.tapestry5.commons.Messages)111 Test (org.testng.annotations.Test)102 BeanModel (org.apache.tapestry5.beanmodel.BeanModel)54 ComponentResources (org.apache.tapestry5.ComponentResources)23 PropertyModel (org.apache.tapestry5.beanmodel.PropertyModel)21 FieldValidator (org.apache.tapestry5.FieldValidator)18 MessageFormatter (org.apache.tapestry5.commons.MessageFormatter)15 FormSupport (org.apache.tapestry5.services.FormSupport)15 FieldValidatorSource (org.apache.tapestry5.services.FieldValidatorSource)14 TypeCoercer (org.apache.tapestry5.commons.services.TypeCoercer)13 Validator (org.apache.tapestry5.Validator)12 Locale (java.util.Locale)11 ValidatorMacro (org.apache.tapestry5.validator.ValidatorMacro)11 Field (org.apache.tapestry5.Field)10 PropertyConduit (org.apache.tapestry5.beanmodel.PropertyConduit)9 AnnotationProvider (org.apache.tapestry5.commons.AnnotationProvider)9 PropertyOverrides (org.apache.tapestry5.PropertyOverrides)7 FieldTranslatorSource (org.apache.tapestry5.services.FieldTranslatorSource)7 TranslatorSource (org.apache.tapestry5.services.TranslatorSource)6 Map (java.util.Map)5