Search in sources :

Example 16 with OptionModel

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

the class OptionGroupForm method getModel.

public SelectModel getModel() {
    return new AbstractSelectModel() {

        private List<OptionGroupModel> groupModels = null;

        public List<OptionModel> getOptions() {
            return null;
        }

        public List<OptionGroupModel> getOptionGroups() {
            if (groupModels == null) {
                computeModel();
            }
            return groupModels;
        }

        private void computeModel() {
            groupModels = new ArrayList<OptionGroupModel>();
            for (Entity entity : entityList) {
                List<OptionModel> options = new ArrayList<OptionModel>();
                options.add(new OptionModelImpl(entity.getLabel(), entity));
                OptionGroupModel groupModel = new OptionGroupModelImpl(entity.getLabel(), false, options);
                groupModels.add(groupModel);
            }
        }
    };
}
Also used : Entity(org.apache.tapestry5.integration.app1.data.Entity) OptionGroupModel(org.apache.tapestry5.OptionGroupModel) OptionModelImpl(org.apache.tapestry5.internal.OptionModelImpl) AbstractSelectModel(org.apache.tapestry5.util.AbstractSelectModel) OptionGroupModelImpl(org.apache.tapestry5.internal.OptionGroupModelImpl) OptionModel(org.apache.tapestry5.OptionModel) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 17 with OptionModel

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

Example 18 with OptionModel

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

the class EnumSelectModelTest method prefixed_name_in_message_catalog.

@Test
public void prefixed_name_in_message_catalog() {
    Messages messages = mockMessages();
    stub_contains(messages, false);
    train_contains(messages, "Stooge.LARRY", true);
    train_get(messages, "Stooge.LARRY", "Mr. Larry Fine");
    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, "Mr. Larry Fine", 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)

Example 19 with OptionModel

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

the class EnumSelectModelTest method unprefixed_name_in_message_catalog.

@Test
public void unprefixed_name_in_message_catalog() {
    Messages messages = mockMessages();
    stub_contains(messages, false);
    train_contains(messages, "MOE", true);
    train_get(messages, "MOE", "Sir Moe Howard");
    replay();
    SelectModel model = new EnumSelectModel(Stooge.class, messages);
    List<OptionModel> options = model.getOptions();
    assertEquals(options.size(), 3);
    checkOption(options, 0, "Sir Moe Howard", 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