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);
}
}
};
}
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();
}
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();
}
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();
}
Aggregations