Search in sources :

Example 1 with OptionModelImpl

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

the class SelectTest method option_attributes.

@Test
public void option_attributes() 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 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("option_attributes.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 2 with OptionModelImpl

use of org.apache.tapestry5.internal.OptionModelImpl 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 3 with OptionModelImpl

use of org.apache.tapestry5.internal.OptionModelImpl 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 4 with OptionModelImpl

use of org.apache.tapestry5.internal.OptionModelImpl 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 5 with OptionModelImpl

use of org.apache.tapestry5.internal.OptionModelImpl 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)

Aggregations

OptionModelImpl (org.apache.tapestry5.internal.OptionModelImpl)5 OptionModel (org.apache.tapestry5.OptionModel)4 SelectModelImpl (org.apache.tapestry5.internal.SelectModelImpl)4 Test (org.testng.annotations.Test)3 XMLMarkupModel (org.apache.tapestry5.dom.XMLMarkupModel)2 MarkupWriterImpl (org.apache.tapestry5.internal.services.MarkupWriterImpl)2 StringValueEncoder (org.apache.tapestry5.internal.services.StringValueEncoder)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 OptionGroupModel (org.apache.tapestry5.OptionGroupModel)1 Entity (org.apache.tapestry5.integration.app1.data.Entity)1 OptionGroupModelImpl (org.apache.tapestry5.internal.OptionGroupModelImpl)1 AbstractSelectModel (org.apache.tapestry5.util.AbstractSelectModel)1