Search in sources :

Example 6 with SelectModelImpl

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

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

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

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

the class SelectTest method empty_model.

@Test
public void empty_model() {
    ValidationTracker tracker = mockValidationTracker();
    Select select = new Select();
    train_getInput(tracker, select, null);
    replay();
    select.setModel(new SelectModelImpl(null, null));
    select.setValidationTracker(tracker);
    select.options(null);
    verify();
}
Also used : SelectModelImpl(org.apache.tapestry5.internal.SelectModelImpl) Test(org.testng.annotations.Test)

Example 10 with SelectModelImpl

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

the class SelectTest method current_selection_from_validation_tracker.

@Test
public void current_selection_from_validation_tracker() throws Exception {
    ValidationTracker tracker = mockValidationTracker();
    List<OptionModel> options = TapestryInternalUtils.toOptionModels("fred=Fred Flintstone,barney=Barney Rubble");
    Select select = new Select();
    train_getInput(tracker, select, "fred");
    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();
    // fred will be selected, not barney, because the validation tracker
    // takes precendence.
    assertEquals(writer.toString(), read("current_selection_from_validation_tracker.txt"));
    verify();
}
Also used : MarkupWriterImpl(org.apache.tapestry5.internal.services.MarkupWriterImpl) SelectModelImpl(org.apache.tapestry5.internal.SelectModelImpl) StringValueEncoder(org.apache.tapestry5.internal.services.StringValueEncoder) XMLMarkupModel(org.apache.tapestry5.dom.XMLMarkupModel) Test(org.testng.annotations.Test)

Aggregations

SelectModelImpl (org.apache.tapestry5.internal.SelectModelImpl)12 Test (org.testng.annotations.Test)10 XMLMarkupModel (org.apache.tapestry5.dom.XMLMarkupModel)9 MarkupWriterImpl (org.apache.tapestry5.internal.services.MarkupWriterImpl)9 StringValueEncoder (org.apache.tapestry5.internal.services.StringValueEncoder)9 OptionModelImpl (org.apache.tapestry5.internal.OptionModelImpl)4 OptionGroupModelImpl (org.apache.tapestry5.internal.OptionGroupModelImpl)3 OptionModel (org.apache.tapestry5.OptionModel)2