use of org.apache.tapestry5.OptionGroupModel 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.OptionGroupModel in project tapestry-5 by apache.
the class SelectTest method option_groups_precede_ungroup_options.
@Test
public void option_groups_precede_ungroup_options() throws Exception {
ValidationTracker tracker = mockValidationTracker();
OptionGroupModel husbands = new OptionGroupModelImpl("Husbands", false, TapestryInternalUtils.toOptionModels("Fred,Barney"));
Select select = new Select();
train_getInput(tracker, select, null);
replay();
select.setModel(new SelectModelImpl(Collections.singletonList(husbands), TapestryInternalUtils.toOptionModels("Wilma,Betty")));
select.setValueEncoder(new StringValueEncoder());
select.setValue("Fred");
select.setValidationTracker(tracker);
MarkupWriter writer = new MarkupWriterImpl(new XMLMarkupModel());
writer.element("select");
select.options(writer);
writer.end();
assertEquals(writer.toString(), read("option_groups_precede_ungroup_options.txt"));
verify();
}
use of org.apache.tapestry5.OptionGroupModel in project tapestry-5 by apache.
the class SelectTest method option_group_attributes.
@Test
public void option_group_attributes() throws Exception {
ValidationTracker tracker = mockValidationTracker();
Map<String, String> attributes = Collections.singletonMap("class", "pixie");
OptionGroupModel husbands = new OptionGroupModelImpl("Husbands", false, TapestryInternalUtils.toOptionModels("Fred,Barney"), attributes);
Select select = new Select();
train_getInput(tracker, select, null);
replay();
select.setModel(new SelectModelImpl(Collections.singletonList(husbands), null));
select.setValueEncoder(new StringValueEncoder());
select.setValue("Fred");
select.setValidationTracker(tracker);
MarkupWriter writer = new MarkupWriterImpl(new XMLMarkupModel());
writer.element("select");
select.options(writer);
writer.end();
assertEquals(writer.toString(), read("option_group_attributes.txt"));
verify();
}
Aggregations