Search in sources :

Example 6 with OptionModel

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

the class SelectTest method disabled_option.

@Test
public void disabled_option() throws Exception {
    ValidationTracker tracker = mockValidationTracker();
    // Extra cast needed for Sun compiler, not Eclipse compiler.
    List<OptionModel> options = Arrays.asList((OptionModel) new OptionModelImpl("Fred", "fred") {

        @Override
        public boolean isDisabled() {
            return true;
        }

        @Override
        public Map<String, String> getAttributes() {
            return Collections.singletonMap("class", "pixie");
        }
    });
    Select select = new Select();
    train_getInput(tracker, select, null);
    replay();
    select.setModel(new SelectModelImpl(null, options));
    select.setValueEncoder(new StringValueEncoder());
    select.setValue("barney");
    select.setValidationTracker(tracker);
    MarkupWriter writer = new MarkupWriterImpl(new XMLMarkupModel());
    writer.element("select");
    select.options(writer);
    writer.end();
    assertEquals(writer.toString(), read("disabled_option.txt"));
    verify();
}
Also used : MarkupWriterImpl(org.apache.tapestry5.internal.services.MarkupWriterImpl) OptionModelImpl(org.apache.tapestry5.internal.OptionModelImpl) SelectModelImpl(org.apache.tapestry5.internal.SelectModelImpl) StringValueEncoder(org.apache.tapestry5.internal.services.StringValueEncoder) XMLMarkupModel(org.apache.tapestry5.dom.XMLMarkupModel) Test(org.testng.annotations.Test)

Example 7 with OptionModel

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

the class ActivationRequestParameterDemo method getClickCountModel.

public SelectModel getClickCountModel() {
    OptionModel one = new OptionModelImpl("one", 1);
    OptionModel two = new OptionModelImpl("two", 2);
    OptionModel three = new OptionModelImpl("three", 3);
    return new SelectModelImpl(one, two, three);
}
Also used : OptionModelImpl(org.apache.tapestry5.internal.OptionModelImpl) SelectModelImpl(org.apache.tapestry5.internal.SelectModelImpl) OptionModel(org.apache.tapestry5.OptionModel)

Example 8 with OptionModel

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

the class OptionModelImplTest method basics.

@Test
public void basics() {
    OptionModel model = new OptionModelImpl("Label", this);
    assertEquals(model.getLabel(), "Label");
    assertFalse(model.isDisabled());
    assertSame(model.getValue(), this);
    assertNull(model.getAttributes());
    model = new OptionModelImpl("Fred", "fred");
    assertEquals(model.toString(), "OptionModel[Fred fred]");
}
Also used : OptionModel(org.apache.tapestry5.OptionModel) Test(org.testng.annotations.Test)

Example 9 with OptionModel

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

the class SelectModelFactoryImpl method createSelectModel.

private SelectModel createSelectModel(List<?> objects, ValueLabelProvider<Object> labelProvider) {
    final List<OptionModel> options = CollectionFactory.newList();
    for (Object object : objects) {
        String label = labelProvider.getLabel(object);
        options.add(new OptionModelImpl(label, object));
    }
    return new SelectModelImpl(null, options);
}
Also used : OptionModelImpl(org.apache.tapestry5.internal.OptionModelImpl) SelectModelImpl(org.apache.tapestry5.internal.SelectModelImpl) OptionModel(org.apache.tapestry5.OptionModel)

Example 10 with OptionModel

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

the class EnumSelectModelTest method generated_labels.

@Test
public void generated_labels() {
    Messages messages = mockMessages();
    stub_contains(messages, false);
    replay();
    SelectModel model = new EnumSelectModel(Stooge.class, messages);
    List<OptionModel> options = model.getOptions();
    assertEquals(options.size(), 3);
    checkOption(options, 0, "Moe", Stooge.MOE);
    checkOption(options, 1, "Larry", Stooge.LARRY);
    checkOption(options, 2, "Curly Joe", Stooge.CURLY_JOE);
    verify();
}
Also used : Messages(org.apache.tapestry5.commons.Messages) OptionModel(org.apache.tapestry5.OptionModel) SelectModel(org.apache.tapestry5.SelectModel) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)15 OptionModel (org.apache.tapestry5.OptionModel)12 SelectModelImpl (org.apache.tapestry5.internal.SelectModelImpl)8 XMLMarkupModel (org.apache.tapestry5.dom.XMLMarkupModel)6 MarkupWriterImpl (org.apache.tapestry5.internal.services.MarkupWriterImpl)6 StringValueEncoder (org.apache.tapestry5.internal.services.StringValueEncoder)6 OptionModelImpl (org.apache.tapestry5.internal.OptionModelImpl)5 OptionGroupModel (org.apache.tapestry5.OptionGroupModel)4 SelectModel (org.apache.tapestry5.SelectModel)4 Messages (org.apache.tapestry5.commons.Messages)4 ArrayList (java.util.ArrayList)1 List (java.util.List)1 TypeCoercer (org.apache.tapestry5.commons.services.TypeCoercer)1 Request (org.apache.tapestry5.http.services.Request)1 Entity (org.apache.tapestry5.integration.app1.data.Entity)1 InternalComponentResources (org.apache.tapestry5.internal.InternalComponentResources)1 OptionGroupModelImpl (org.apache.tapestry5.internal.OptionGroupModelImpl)1 LocalizationSetter (org.apache.tapestry5.services.LocalizationSetter)1 ValueEncoderSource (org.apache.tapestry5.services.ValueEncoderSource)1 AbstractSelectModel (org.apache.tapestry5.util.AbstractSelectModel)1